How can I delete multiple rows in a DataGridView
using a CheckBox
?
I could not find where I do mistakes, but the code throws an error which explains not defined the parameters.
DataGridViewRow row = new DataGridViewRow();
SqlCommand delcommand = new SqlCommand();
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
row = dataGridView1.Rows[i];
if (Convert.ToBoolean(row.Cells[10].Value) == true)
{
int id = Convert.ToInt16(dataGridView1.SelectedRows[dataGridView1.SelectedCells[0].RowIndex].Cells[0].Value);
delcommand.Connection = connection;
delcommand.CommandText = "DELETE FROM TFirmaBilgileri WHERE id = '" +
dataGridView1.CurrentRow.Cells[0].Value.ToString() + "'";
delcommand.CommandType = CommandType.Text;
delcommand.ExecuteNonQuery();
dataGridView1.Rows.RemoveAt(dataGridView1.SelectedCells[i].RowIndex);
i--;
}
}
connection.close();