gpt4 book ai didi

mysql - 从数据库中删除datagridview中的数据

转载 作者:行者123 更新时间:2023-11-30 22:06:48 26 4
gpt4 key购买 nike

下面是我用来从数据库中删除 datagridview 中的数据的代码,但我遇到了一个错误:

enter image description here

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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com