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 copy As new System.Data.SqlClient.SqlBulkCopy(conn, System.Data.SqlClient.SqlBulkCopyOptions.Default, tran)
For Each dc As DataCol In DataTables(e.form.name & "_Table1").datacols
Dim mapping1 As new System.Data.SqlClient.SqlBulkCopyColumnMapping(dc.name, dc.name)
Copy.ColumnMappings.Add(mapping1)
Next
copy.Destinati '指定服务器上目标表的名称
copy.BatchSize = 1000
copy.WriteToServer(DataTables(e.form.name & "_Table1").basetable) '原来是加载的数据表就没问题,现在此表是查询后绑定到窗口的表执行出题
tran.Commit() '提交事务
msgbox("OK")
catch ex As exception
msgbox(ex.message)
tran.Rollback() '返回False 执行失败!
End try
原来是加载的数据表就没问题,现在窗口表是如下获得的
Dim cmd As New SQLCommand
cmd.ConnectionName = Mydata
cmd.CommandTimeOut = 300
cmd.CommandText = "Exec usp_mps20"
Dim dt As DataTable = cmd.ExecuteReader
Dim tbl As Table = Tables(e.form.name & "_Table1")
tbl.DataSource = dt
这种情况红色那句要怎么写才行?现在执行或提示 "给定的 ColumnMapping 与源或目标中的任意列均不匹配"
无法执行
谢谢!