Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 尝试更新数据库时发生动态sql生成错误_Vb.net - Fatal编程技术网

Vb.net 尝试更新数据库时发生动态sql生成错误

Vb.net 尝试更新数据库时发生动态sql生成错误,vb.net,Vb.net,我遵循您的代码,并将其放入msgbox进行确认,是的,它返回正确的行号。但是,我的代码出现了一个错误:Private Sub Button2\u Click(ByVal sender作为System.Object,ByVal e作为System.EventArgs)处理按钮2。单击 将cb设置为新的OleDb.OleDbCommandBuilder(da)命令生成器以更新数据库 ds.Tables("inventory_table").Rows(marker).Item(0) = Tex

我遵循您的代码,并将其放入msgbox进行确认,是的,它返回正确的行号。但是,我的代码出现了一个错误:Private Sub Button2\u Click(ByVal sender作为System.Object,ByVal e作为System.EventArgs)处理按钮2。单击 将cb设置为新的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?      

在双击事件中,设置一个全局变量:

_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