Dim tran As System.Data.SqlClient.SqlTransaction
try
Dim conn As new System.Data.SqlClient.SqlConnection("*****") '改为自己数据库的连接字符串
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 mapping7 As new System.Data.SqlClient.SqlBulkCopyColumnMapping("仓库", "仓库")
Dim mapping8 As new System.Data.SqlClient.SqlBulkCopyColumnMapping("货位", "货位")
Dim mapping9 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.ColumnMappings.Add(mapping7)
Copy.ColumnMappings.Add(mapping8)
Copy.ColumnMappings.Add(mapping9)
copy.Destinati '指定服务器上目标表的名称
copy.BatchSize = 1000
copy.WriteToServer(DataTables("导入待入库审核").basetable) '你的datatable名字,执行把DataTable中的数据写入DB
tran.Commit() '提交事务
msgbox("导入成功!")
catch ex As exception
msgbox(ex.message)
tran.Rollback() '返回False 执行失败!