我正在尝试从datagrid视图和数据库中删除所选行。我的代码是从datagridview中删除而不是从实际数据库中删除,我有什么问题吗?
private void btnDelRecord_Click(object sender, EventArgs e)
{
for (int i = 0; i < dataGridView2.Rows.Count; i++)
{
DataGridViewRow dr = dataGridView2.Rows[i];
if (dr.Selected == true)
{
dataGridView2.Rows.RemoveAt(i);
Query = "Delete from TblEmployer where Id=" + i + "";
theReader = conn.ExecuteStatement(Query);
conn.CloseConnection();
MessageBox.Show("Deleted");
}
}
谢谢