网络编程
位置:首页>> 网络编程>> 数据库>> SQL Server数据库导入MySQL数据库体验(2)

SQL Server数据库导入MySQL数据库体验(2)

作者:shanjin  发布时间:2009-01-20 16:07:00 

标签:

以上两个是分别采用php脚本和asp脚本对user表的数据进行由sql server到mysql的导入其间我采用2种回避的方法来避免ntext,image类型数据的传递,一种是将ntext字段改为nvarchar(4000),因为实际情况,原始数据中该字段的数据长度都未超过4000个字,所以并没有出现数据截断,另一个手段是将image类型数据取出来写到文件中,以文件形式保存,将文件路径存到数据库中,方法见下:

  
  function makeattach(fileContentType,filevalue,i)
  select case fileContentType
  case "application/msword"
  ext="doc"
  
  case "application/vnd.ms-excel"
  ext="exl"
  
  case "application/vnd.ms-powerpoint"
  ext="pps"
  
  case "application/x-rar-compressed"
  ext="rar"
  
  case "application/x-zip-compressed"
  ext="zip"
  
  case "image/gif"
  ext="gif"
  
  case "image/pjpeg"
  ext="jpg"
  
  case "text/plain"
  ext="txt"
  
  case else
  ext="x"
  
  end select
  if ext<>"x" then
  set fso=server.createobject("FileSystemObject")
  fName="attech"&i&"."&ext
  Dir="d:attach"
  If fso.FileExists(Dir & fName) Then fso.deletefile Dir & fName
  If fName<>"" AND NOT fso.FileExists(Dir & fName) Then
  Set strm1=Server.CreateObject("ADODB.Stream")
  strm1.Open
  strm1.Type=1 'Binary
  strm1.Write filevalue
  strm1.SaveToFile Dir & fName,2
  Set strm1=Nothing
  end if
  makeattach=fName
  end if
  end function

这个函数有3个输入参数,第一个是文件的contentType,第二个是文件的二进制数值,第三个是个可以区别文件名的变量,先根据contentType确定所存文件的后缀名,然后就是将二进制数值保存成指定文件名的文件,并将文件名作为输出参数返回,将返回的参数作为数据写到mysql的数据库中保存,好了大功告成。

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com