Excel数据导入到SQL里时出现数据类型错误怎么解决
在Excel里有一列为文本的数据例如:1234567890
对应的SQL里也有一字段(假设为netID)为nvarchar
当把Excel里的收据导到SQL以后pwd里怎么变为科学记数法的形式了,怎么样才能使SQL里的数据与Excel一样?
用cstr(excelrs(0))这一方法也没有用,
下面是导入的部分程序:
set sqlconn=server.createobject( "ADODB.connection ")
sqlconn.open "Provider=SQLOLEDB;Data Source= ' " & (serverip) & " ';Initial Catalog=mysql;User ID=sa;Password= ' " & (pwd) & " ' "
set excelconn=server.createobject( "ADODB.connection ")
excelconn.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= ' " & (excelfile) & " ';Extended Properties= " "Excel 8.0;HDR=yes;IMEX=1 " " " 'HDR=YES表示除了标题,=NO表示包括标题
set excelrs=server.createobject( "adodb.recordset ")
excelrs.open "select * from [Sheet1$] ",excelconn,1,1
do while not excelrs.eof
set sql=sqlconn.execute( "select * from net_xf where net= ' "&(excelrs(0))& " ' and lastday= ' "&(excelrs(2))& " ' ") '如果数据库里帐号、失效日期和电子表格里相同则不写入数据
if sql.eof then
rt.open "select * from net where netID= ' "&(excelrs(0))& " ' ",Conn,1,1
if rt.eof then
area=excelrs(1)
else
area=rt( "area ")
end if
rt.close
sqlconn.execute( "insert into net_xf (net,area,lastday,noteday) values( ' "&excelrs(0)& " ', ' "&(area)& " ', ' "&excelrs(2)& " ', ' "&(dated)& " ') ")
end if
excelrs.movenext
loop
------解决方案--------------------Excel数据导入到SQL时,它是根据最小的ID的字段来匹配的
如果,第一个ID的某个字段为“123456”导入到SQL里,会把这个字段表示为 "int "型
------解决方案--------------------http://www.zzcx.net.cn/