顾名思义,BulkCopy,就是批量复制的意思,只适合批量新增数据
设置一下BatchSize,性能会更上一层,BatchSize一般在500~1000之间,性能相对可靠一点
Dim tran As System.Data.SqlClient.SqlTransaction
try
Dim conn As new System.Data.SqlClient.SqlConnection("server=voyo;uid=sa;pwd=hailun.;database=Test")
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.DestinationTableName = "表D" '指定服务器上目标表的名称
copy.BatchSize = 1000
copy.WriteToServer(DataTables("表D").basetable) '你的datatable名字,执行把DataTable中的数据写入DB
tran.Commit() '提交事务
msgbox("OK")
catch ex As exception
msgbox(ex.message)
tran.Rollback() '返回False 执行失败!
End try