Dim tran As System.Data.SqlClient.SqlTransaction
Try
Dim conn As New System.Data.SqlClient.SqlConnection("server=192.168.1.10;uid=Sa;pwd=Ab234567;database = 条码扫描系统数据库") '改为自己数据库的连接字符串
conn.Open() '打开链接
tran = conn.BeginTransaction()
Dim mapping1 As New System.Data.SqlClient.SqlBulkCopyColumnMapping("月份", "月份") '改为自己的列名,有多少列就增加多少个
Dim mapping2 As New System.Data.SqlClient.SqlBulkCopyColumnMapping("项目", "项目")
Dim mapping3 As New System.Data.SqlClient.SqlBulkCopyColumnMapping("费用明细", "费用明细")
Dim mapping4 As New System.Data.SqlClient.SqlBulkCopyColumnMapping("金额", "金额")
Dim mapping5 As New System.Data.SqlClient.SqlBulkCopyColumnMapping("分配方式", "分配方式")
Dim mapping6 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.ColumnMappings.Add(mapping3)
Copy.ColumnMappings.Add(mapping4)
Copy.ColumnMappings.Add(mapping5)
Copy.ColumnMappings.Add(mapping6)
copy.Destinati '指定服务器上目标表的名称
copy.BatchSize = 1000
copy.WriteToServer(DataTables("生产成本总表").basetable) '你的datatable名字,执行把DataTable中的数据写入DB
tran.Commit() '提交事务
msgbox("OK")
Catch ex As exception
msgbox(ex.message)
tran.Rollback() '返回False 执行失败!
End Try
DataTables("生产成本临时表").Save()