DataTables("采购记录").Load '加载新的查询表
'开始快速导入
Dim tran As System.Data.SqlClient.SqlTransaction
try
Dim conn As new System.Data.SqlClient.SqlConnection("server=连接字符串省略”) '改为自己数据库的连接字符串
conn.Open() '打开链接
tran = conn.BeginTransaction()
Dim copy As new System.Data.SqlClient.SqlBulkCopy(conn, System.Data.SqlClient.SqlBulkCopyOptions.Default, tran)
For Each dc As DataCol In DataTables("采购记录").datacols
Dim mapping1 As new System.Data.SqlClient.SqlBulkCopyColumnMapping(dc.name, dc.name)
Copy.ColumnMappings.Add(mapping1)
Next
copy.DestinationTableName=tb1name '指定服务器上目标表的名称
copy.BatchSize = 1000
copy.WriteToServer(DataTables("采购记录").basetable)
tran.Commit() '提交事务
Forms("采购发送").Open()
catch ex As exception
msgbox(ex.message)
tran.Rollback() '返回False 执行失败!
End try
出错信息是:The given value of type string from the deta source cannot be converted
to type nvarchar of the specified target column.
这个项目文件在多台电脑抓取多个数据库记录上传都没有问题,这个电脑安装运行时出现了问题,另外因为是2008数据库 运行了sqlncli_x64程序,但设置数据源的时候,发现还是没有SQL SERVER Native Client 10.0 这个驱动,但项目可以连上mssql2008数据库。
不知问题出在哪里?如何解决。多谢指导!