在论坛中找到如下事件代码,是遍历表A,然后把表中数据写入表D
怎么实现遍历本地 a.mdb 文件,然后遍历这个文件中的表A ,再把数据写入表D 呢?
Dim tran As System.Data.SqlClient.SqlTransactiontry 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("表A").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("表D").basetable) '你的datatable名字,执行把DataTable中的数据写入DB tran.Commit() '提交事务 msgbox("OK")catch ex As exception msgbox(ex.message) tran.Rollback() '返回False 执行失败!End try