下面是我用来从数据库中删除 datagridview 中的数据的代码,但我遇到了一个错误:
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Try
con.Open()
For i As Integer = Me.DataGridView1.SelectedRows.Count - 1 To 0 Step -1
CmdDelete = "DELETE rsdcpatienttbl WHERE TreatmentCount='" & Me.DataGridView1.SelectedRows(i).Cells(0).Value.ToString() & "'"
adapter = New MySqlDataAdapter(CmdDelete, con)
ds = New DataSet()
adapter.Fill(ds)
Me.DataGridView1.Rows.Remove(Me.DataGridView1.SelectedRows(i))
Next
load_table()
MessageBox.Show("Deleted Successfully.", "Informed", MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch ex As Exception
MessageBox.Show(ex.ToString())
End Try
End Sub
最佳答案
如果您使用 MySqlDataAdapter
执行该操作,那么您不需要单独打开连接,删除 con.Open()
以跳过您遇到的异常
关于mysql - 从数据库中删除datagridview中的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41430067/