C#删除数据库记录不能删除一个,只能删除两个或两个以上 在线等
英雄在线 2009-03-27 09:15:43 if (MessageBox.Show("确定要删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
int chkCount = 0;
for (int i = 0; i < this.dgvGatherInfo.Rows.Count; i++)
{
if (this.dgvGatherInfo.Rows[i].Cells[0].Value != null) //判断该行的复选框是否存在
{
if (this.dgvGatherInfo.Rows[i].Cells[0].Value.ToString() == "True") //判断该复选框是否被选中
{
gaRule.GatherInfoDel(Convert.ToInt32(this.dgvGatherInfo.Rows[i].Cells[1].Value));
}
chkCount++;
}
}
if (chkCount == 0)
{
MessageBox.Show("请选择要删除的行!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
MessageBox.Show("删除成功!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.FormGatherInfo_Load(this,null);
生成通过,运行程序的话在checkbox选择,要选两个或两个以上才能执行删除,选一个的话会提示叫你“选择要删除的行”
调试的时候 只在一个checkbox打勾,程序运行到if (this.dgvGatherInfo.Rows[i].Cells[0].Value != null) //判断该行的复选框是否存在 就会直接跳过到if (chkCount == 0)
不知道怎么回事
大家帮忙看下