困扰2天了,求帮助:vb.net中将dataset导入到access数据库的问题
我想将datagirdview1里的数据导入到access中PrivateSubButton7_Click(ByValsenderAsSystem.Object,ByVa...
我想将datagirdview1里的数据导入到access中
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
Dim con As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=f:\\vb2010学习.mdb")
Dim conncom As New OleDb.OleDbCommand("select * from [ex]", con) '这是个空表
Dim t As New DataSet
Dim connAdapter As New OleDb.OleDbDataAdapter(conncom)
Dim builder As OleDb.OleDbCommandBuilder = New OleDb.OleDbCommandBuilder(connAdapter)
connAdapter.Fill(t, "[ex]")
Dim d As DataSet = DataGridView1.DataSource
For Each tem As DataRow In d.Tables(0).Rows
t.Tables(0).ImportRow(tem)
Next
TextBox2.Text = connAdapter.Update(t, "[ex]")
'结果为0,没能更新数据,
DataGridView2.DataSource = t.Tables(0)
'能看到我要添加的数据,说明已经加到t里面了
End Sub
为什么添加进了t这个dataset,却更新不到ex这个表里啊? 展开
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
Dim con As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=f:\\vb2010学习.mdb")
Dim conncom As New OleDb.OleDbCommand("select * from [ex]", con) '这是个空表
Dim t As New DataSet
Dim connAdapter As New OleDb.OleDbDataAdapter(conncom)
Dim builder As OleDb.OleDbCommandBuilder = New OleDb.OleDbCommandBuilder(connAdapter)
connAdapter.Fill(t, "[ex]")
Dim d As DataSet = DataGridView1.DataSource
For Each tem As DataRow In d.Tables(0).Rows
t.Tables(0).ImportRow(tem)
Next
TextBox2.Text = connAdapter.Update(t, "[ex]")
'结果为0,没能更新数据,
DataGridView2.DataSource = t.Tables(0)
'能看到我要添加的数据,说明已经加到t里面了
End Sub
为什么添加进了t这个dataset,却更新不到ex这个表里啊? 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询