确认删除记录 [英] Confirmation of Deleteing record
本文介绍了确认删除记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个组合框,我可以在Access数据库中获取显示记录,然后我也可以删除记录!
按钮功能正常,代码就是这样!
I have a combo Box where I can get display record in Access Database and then I can also delete the record !
The button function works fine and the code is like this !
private void btnDelete_Click(object sender, EventArgs e)
{
Person p = new Person();
p = cmbPersons.SelectedItem as Person;
b.Delete(p);
}
现在我想在点击按钮时添加确认,包含abc的数据已经包含已被删除
我的问题是,我是否需要在此按钮部分添加内容?或者我还需要在这部分添加一些东西?
Now I want to add a confirmation when button is clicked, " The data containing abc has been deleted"
My question is do I need to add something only in this button part ? or I need to add something in this part also ?
public void Delete(Person p)
{
try
{
command.CommandText = "DELETE FROM TPersons WHERE ID= "+p.Id;
command.CommandType = CommandType.Text;
connection.Open();
command.ExecuteNonQuery();
}
catch (Exception)
{
throw;
}
finally
{
if (connection != null)
{
connection.Close();
}
}
}
推荐答案
ExecuteNonQuery返回一个包含受影响的行数的int你可以在你的查询执行周围放一个if语句
ExecuteNonQuery returns an int containing the number of rows affected so you could just put an if statement around your query execution
if(command.ExecuteNonQuery() > 0)
{
MessageBox.Show("Person deleted");
}
else
{
MessageBox.show("Person not found");
}
将下面的代码添加到btnDelete按钮:
OnClientClick = 返回确认('您确定要删除所选项吗?');
Add Below code into "btnDelete" button :
OnClientClick = "return confirm('Are you sure you want to delete the selected Item?');"
您只能在按钮部分添加它。
You can add it only in the button part.
这篇关于确认删除记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文