[英]deleting data via datagrid view mySQL Vb.net
When I click the delete button, the data in the mysqldatabase is deleted but the data in the datagridview is still there. 当我单击删除按钮时,mysqldatabase中的数据被删除,但datagridview中的数据仍然存在。 How can I delete the data in the datagridview?
如何删除datagridview中的数据?
This is my code 这是我的代码
cmd.CommandText = "delete from pawn where category = '" & txtCategory.Text & "'"
dr = cmd.ExecuteReader
You can add two buttons, button Delete and button Update to your form.After that you can add the event handler as follows. 您可以在窗体中添加两个按钮,即“删除”按钮和“更新”按钮。之后,可以按如下所示添加事件处理程序。
Private Sub delete_btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles delete_btn.Click
If MessageBox.Show("Do you want to delete this row ?", "Delete", MessageBoxButtons.YesNo) = DialogResult.Yes Then
DataGridView1.Rows.RemoveAt(DataGridView1.SelectedRows(0).Index)
'yourdatadaptername'.Update('yourdatatablename')
End If
End Sub
Private Sub save_btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles save_btn.Click
'yourdatadaptername'.Update('yourdatatablename')
End Sub
End Class 末级
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.