老师,
Dim tran As System.Data.SqlClient.SqlTransaction
try
Dim conn As new System.Data.SqlClient.SqlConnection("server=10.11.2.31;uid=sa;pwd=acea.1222223;database=U2216")
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("Bom").datacols
Dim mapping1 As new System.Data.SqlClient.SqlBulkCopyColumnMapping(dc.name, dc.name)
Copy.ColumnMappings.Add(mapping1)
Next
copy.Destinati '指定服务器上目标表的名称
copy.BatchSize = 3000
copy.WriteToServer(DataTables("Bb").basetable) '你的datatable名字,执行把DataTable中的数据写入DB
tran.Commit() '提交事务
catch ex As exception
msgbox(ex.message)
tran.Rollback() '返回False 执行失败!
End try
[此贴子已经被作者于2023/4/17 20:31:15编辑过]