第1个回答 2010-04-21
/// <summary>
/// 删除
/// </summary>
private void bindingNavigatorDeleteItem_Click(object sender, EventArgs e)
{
#region Shift多行删除
if (this.dataGridView1.SelectedRows.Count > 0)
{
if (MessageBox.Show("确定要删除选中的员工信息吗?删除后将不可恢复!", "小鱼提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
Del();
}
}
else
{
MessageBox.Show("请选择要删除的员工信息!", "小鱼提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
#endregion
}
/// <summary>
/// 删除的方法
/// </summary>
public void Del()
{
int k = this.dataGridView1.SelectedRows.Count;
if (dataGridView1.Rows.Count > 0)
{
for (int i = k; i >= 1; i--)//从下往上删,避免沙漏效应
{
string usercode = dataGridView1.SelectedRows[i - 1].Cells["UCode"].Value.ToString();
if(userbll.DelUser(usercode))
{
}
else
{
MessageBox.Show("删除失败!", "小鱼提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
this.dataGridView1.Rows.RemoveAt(dataGridView1.SelectedRows[i - 1].Index);
}
}
else
{
dataGridView1.Rows.Clear();
}
}
第2个回答 2010-04-21
看不到你的代码,只能给你个思路,删除行的时候得到当前的数据ID(前提是绑定的时候绑定ID 可以隐藏掉)执行SQL语句即可
第3个回答 2010-04-28
//删除操作
private void deleteBtn_Click(object sender, EventArgs e)
{
try
{
if (this.customerGridView.Rows.Count <= 0)
{
MessageBox.Show("没有要删除的内容");
}
else
{
DialogResult result = MessageBox.Show("确认删除此条记录?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (result == DialogResult.Yes)
{
string delete_No = this.customerGridView.SelectedRows[0].Cells["客户编号"].Value.ToString();
string sql_str_delete = "delete from customerInfo where 客户编号='" + delete_No + "'";
SqlConnection conn = dbManage.getcon();
SqlCommand com = new SqlCommand(sql_str_delete, conn);
int flag = dbManage.ExeSQL(sql_str_delete);
if (flag == 0)
{
this.customerGridView.Rows.RemoveAt(this.customerGridView.SelectedRows[0].Index);
MessageBox.Show("记录已成功删除", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
}
catch (SqlException ex)
{
MessageBox.Show(ex.ToString());
}
}