此主题相关图片如下:错误提示.png
Dim tran As System.Data.SqlClient.SqlTransaction
try
Dim conn As new System.Data.SqlClient.SqlConnection("Provider=SQLOLEDB.1;Password=cwsa;Persist Security Info=True;User ID=sa;Initial Catalog=K3cx2016;Data Source=cwserver2017") '改为自己数据库的连接字符串
conn.Open() '打开链接
tran = conn.BeginTransaction()
Dim mapping1 As new System.Data.SqlClient.SqlBulkCopyColumnMapping("序号", "订单编号","件号","业务件号","数量","已领数量","不含税价","税率","已领金额","应发金额","供料属性","特别单价","计划下达时间","总成批次") '改为自己的列名,有多少列就增加多少个
Dim mapping2 As new System.Data.SqlClient.SqlBulkCopyColumnMapping("序号", "订单编号","件号","业务件号","数量","已领数量","不含税价","税率","已领金额","应发金额","供料属性","特别单价","计划下达时间","总成批次")
Dim copy As new System.Data.SqlClient.SqlBulkCopy(conn, System.Data.SqlClient.SqlBulkCopyOptions.Default, tran)
Copy.ColumnMappings.Add(mapping1)
Copy.ColumnMappings.Add(mapping2)
copy.Destinati '指定服务器上目标表的名称
copy.BatchSize = 1000
copy.WriteToServer(DataTables("PEBS外购投料").basetable) '你的datatable名字,执行把DataTable中的数据写入DB
tran.Commit() '提交事务
msgbox("OK")
catch ex As exception
msgbox(ex.message)
tran.Rollback() '返回False 执行失败!
End try
参考并修改了代码,但提示这个错误,请问是我哪里还没有注意到?