如何更新datagridview中的选定行?

时间:2017-03-01 16:10:31

标签: vb.net datagridview

我正在尝试更新datagridview上所选行的数据,但是当我点击“更新”按钮时,所有数据甚至是未选中的行都被编辑了。

这是我的代码:

connect.Open()
        DataGridView1.SelectedRows(0).Cells(1).Value = TextBox8.Text
        DataGridView1.SelectedRows(0).Cells(2).Value = TextBox1.Text
        DataGridView1.SelectedRows(0).Cells(3).Value = TextBox2.Text
        DataGridView1.SelectedRows(0).Cells(4).Value = TextBox3.Text
        DataGridView1.SelectedRows(0).Cells(5).Value = TextBox4.Text
        DataGridView1.SelectedRows(0).Cells(6).Value = TextBox5.Text
        DataGridView1.SelectedRows(0).Cells(7).Value = TextBox6.Text
        DataGridView1.SelectedRows(0).Cells(8).Value = ComboBox1.Text
        DataGridView1.SelectedRows(0).Cells(9).Value = TextBox9.Text

        da = New MySqlDataAdapter("Select * from tbl_book_info", connect)
        cmd.CommandText = "update tbl_book_info set Title = '" & TextBox1.Text & "',Author = '" & TextBox2.Text & "',Copyright = '" & TextBox3.Text & "',Publisher = '" & TextBox4.Text & "',Place = '" & TextBox5.Text & "',Copies = '" & TextBox6.Text & "',Subject = '" & ComboBox1.Text & "',ClassNo = '" & TextBox8.Text & "',Registered = '" & TextBox9.Text & "',Time = '" & TextBox10.Text & "',Date = '" & TextBox11.Text & "' where ISBN = ISBN "
        cmd.ExecuteNonQuery()
        MsgBox("Data Saved!")
        EDIT.Text = "Edit"

        data = New DataTable()
        DataGridView1.DataSource = data

        da = New MySqlDataAdapter("Select * from tbl_book_info", connect)
        da.Fill(data)

请帮助..我是vb.net的初学者

0 个答案:

没有答案