如何将DataTable中的数据写入到Access数据库中一个结构不相同的表
如何将DataTable中的数据写入到Access数据库中一个结构不相同的表,因为每次datatable的结构是动态的,但是access表中的字段一定全部包括datatable中的字段的,怎么写导入呢下面这个表只能写入结构相同的表,需要怎么改一下?
Dim cmd1 As String = "Select * from [临时表]"
Dim objcmd1 As OleDb.OleDbCommand = New OleDb.OleDbCommand(cmd1, objcon)
Dim da As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter(objcmd1)
Dim dt As DataTable = New DataTable
da.SelectCommand = objcmd1
da.Fill(dt)
dt = mydt
' objcmd1.ExecuteNonQuery()
Dim cb As OleDb.OleDbCommandBuilder = New OleDb.OleDbCommandBuilder(da)
da.Update(dt)
objcon.Close() --------------------编程问答-------------------- Dim cmd1 As String = "Select * from [临时表]"
Dim objcmd1 As OleDb.OleDbCommand = New OleDb.OleDbCommand(cmd1, objcon)
Dim da As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter(objcmd1)
Dim dt As DataTable = New DataTable
da.SelectCommand = objcmd1
da.Fill(dt)
for row as datarow in mydt.rows
dim NewRow as dataRow=dt.NewRow
for i=0 to newRow.items.cout-1
'对相同字段的值进行复制值
NewRow.item(i)=row.item(NewRow.item(i).name)
next
dt.rows.add(NewRow)
next
' objcmd1.ExecuteNonQuery()
Dim cb As OleDb.OleDbCommandBuilder = New OleDb.OleDbCommandBuilder(da)
da.Update(dt)
objcon.Close() --------------------编程问答-------------------- for row as datarow in mydt.rows 中少了 each
补充:.NET技术 , VB.NET