我有問題,當我用此按鈕刪除multichecked行。它只刪除第一行。 cell_dellklient是dataGridView1複選框的名字 肯定是複選框的真正價值c#datagrid複選框多刪除
請幫
public void button2_Click(object sender, EventArgs e)
{
foreach (DataGridViewRow row in dataGridView1.Rows)
{
con.Open();
object cell = row.Cells["cell_delklient"].Value;
if (cell == "yes")
{
SqlCommand cmd = new SqlCommand("Delete From Klienci where Nazwa ='" + row.Cells[0].Value.ToString() + "'", con);
cmd.ExecuteNonQuery();
con.Close();
wyczytywaniegridu();
}
con.Close();
}
}
你爲什麼在每次迭代打開連接一次,關閉它兩次每次迭代? –