我按照你的代码,我把它设置为msgbox确认,是的,它返回正确的行号。但是这里出现错误是我的代码:Private Sub Button2_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)Handles Button2.Click Dim cb As New OleDb.OleDbCommandBuilder(da)'命令构建器来更新数据库
ds.Tables("inventory_table").Rows(marker).Item(0) = TextBox1.Text 'update dataset
ds.Tables("inventory_table").Rows(marker).Item(1) = TextBox2.Text 'update dataset
ds.Tables("inventory_table").Rows(marker).Item(2) = TextBox3.Text 'update dataset
ds.Tables("inventory_table").Rows(marker).Item(3) = TextBox4.Text 'update dataset
ds.Tables("inventory_table").Rows(marker).Item(4) = TextBox5.Text 'update dataset
ds.Tables("inventory_table").Rows(marker).Item(5) = TextBox6.Text 'update dataset
ds.Tables("inventory_table").Rows(marker).Item(6) = TextBox7.Text 'update dataset
da.Update(ds, "inventory_table") 'this is where the updating of database takes place
MsgBox("Data updated")
End Sub
Private Sub DataGridView1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.DoubleClick
TextBox1.Text = DataGridView1.SelectedRows(0).Cells(0).Value
TextBox2.Text = DataGridView1.SelectedRows(0).Cells(1).Value
TextBox3.Text = DataGridView1.SelectedRows(0).Cells(2).Value
TextBox4.Text = DataGridView1.SelectedRows(0).Cells(3).Value
TextBox5.Text = DataGridView1.SelectedRows(0).Cells(4).Value
TextBox6.Text = DataGridView1.SelectedRows(0).Cells(5).Value
TextBox7.Text = DataGridView1.SelectedRows(0).Cells(6).Value
marker = Me.DataGridView1.SelectedRows(0).Index
MsgBox(marker)
End Sub The error says"dynamic sql generation for the updatecommand is not supporyed against a selectcommand that does not return any key column information and ghe line da.update(ds, "inventory_table") is highlighted, can you help me please?
答案 0 :(得分:0)
在双击事件中设置一个全局变量:
_rowIndex = DataGridView1.SelectedRows(0).Index
然后
ds.Tables("inventory_table").Rows(_rowIndex).Item(1) = TextBox1.Text
ds.Tables("inventory_table").Rows(_rowIndex).Item(2) = TextBox2.Text
ds.Tables("inventory_table").Rows(_rowIndex).Item(3) = TextBox3.Text
ds.Tables("inventory_table").Rows(_rowIndex).Item(4) = TextBox4.Text
ds.Tables("inventory_table").Rows(_rowIndex).Item(5) = TextBox5.Text
ds.Tables("inventory_table").Rows(_rowIndex).Item(6) = TextBox6.Text
ds.Tables("inventory_table").Rows(_rowIndex).Item(7) = TextBox7.Text