I have a form with a DataGridView
and a delete Button
and I have this code for delete a row, how can make this delete saved to the database? I filled t
Suppose in your Table
you have a column named id
and you want to delete from database based on id
. Try this:
private void btnDelete_Click(object sender, EventArgs e)
{
foreach (DataGridViewRow item in dataGridView1.SelectedRows)
{
var id = item.Cells[0].Value.ToString();//You can change id and Cells[0] as your need
//Write Delete code like this (Delete from Table where id = @id)
dataGridView1.Rows.RemoveAt(item.Index);//Remove from dataGridView1
}
}