When I click the delete button, the data in the mysqldatabase is deleted but the data in the datagridview is still there. How can I delete the data in the 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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.