第一种用法,按照注释改改,自己测试,还是看不懂的,回头学学vb.net的基础
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
第二种用法,还是看不懂的回头看看帮助【编程基础】和【Foxtable编程】这2章内容
‘函数的参数用法看函数代码注释,改为自己的表名和列名进行测试
Dim strlist As List(Of String) = Functions.Execute("sql提取函数",Tables("凭证"),"凭证","_Identify","[_Identify]","摘要|科目名称|科目编码|部门编码|供应商名称","摘要|科目名称|科目编码|部门编码|供应商名称",1)
Dim sql As String
Dim cmd As New SQLCommand
cmd.C
Dim Count As Integer = 0
try
Connections("cs").BeginTransaction
For Each s As String In strlist
cmd.CommandText = s
Count += cmd.ExecuteNonQuery()
output.show(s)
Next
Connections("cs").Commit '提交事务,所有操作生效
Catch ex As Exception '如果出错
msgbox(ex.message)
Connections("cs").Rollback() '回滚事务,撤销所有操作
End Try
Tables("凭证").DataTable.BaseTable.AcceptChanges() '提交修改