I use this code to delete records which is selected by checkbox
in the datagridview
, bout it take too long time to do the command
private void delete_Click(object sender, EventArgs e)
{
foreach(DataGridViewRow item in advancedDataGridView1.Rows)
{
if(bool.Parse(item.Cells[0].Value.ToString()))
{
conn.Open();
SqlCommand cmd = new SqlCommand("delete from tabl where id = '" + item.Cells[1].Value.ToString() + "'", conn);
cmd.ExecuteNonQuery();
conn.Close();
}
}
MessageBox.Show("Successfully Deleted....");
}
and I use this code for the checkbox
private void Chkselectall_CheckedChanged(object sender, EventArgs e)
{
for(int n = 0; n< advancedDataGridView1.Rows.Count;n++)
{
advancedDataGridView1.Rows[n].Cells[0].Value = chkselectall.Checked;
}
}
What should I do the solve this problem?