You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
1.4 KiB
34 lines
1.4 KiB
//删除图书模块实现
|
|
private void delete_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
//用户点击需要删除的图书,点击删除,弹出是否确认删除的提示信息
|
|
string id = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
|
|
label2.Text = id + dataGridView1.SelectedRows[0].Cells[1].Value.ToString;
|
|
|
|
DialogResult dr = MessageBox.Show("确认删除吗?", "信息提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
|
|
if (dr == DialogResult.OK)
|
|
{
|
|
string sql = $"delete from t_book where id='{id}'";
|
|
Dao1 dao1 = new Dao1();
|
|
if (dao1.Execute(sql) > 0)
|
|
{
|
|
MessageBox.Show("删除成功!");
|
|
Table();
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show("删除失败!" + sql);
|
|
|
|
}
|
|
dao1.DaoClose();
|
|
}
|
|
}
|
|
//若用户没有选择图书点击删除,则弹出提示信息:请先在表格中选中要删除的图书记录
|
|
catch
|
|
{
|
|
MessageBox.Show("请先在表格中选中要删除的图书记录", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
}
|
|
} |