从datagridview中删除记录 [英] delete record from datagridview
本文介绍了从datagridview中删除记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个连接到数据库的datagrigview。我想从datagridview删除记录,如果我选择记录并按删除按钮删除记录,但如果我关闭应用程序并再次启动它仍然会出现记录,我所选择的记录已被删除。
可以任何人告诉我什么是错的..
I have a datagrigview connected to a database. I want to delete record from datagridview, if i select record and press the delete button the record deleted, But if i close app and start it again the record still appear and the record below i selected has been deleted.
can any one tell me what's wrong..
dataadapter.DeleteCommand = new SqlCeCommand("delete from Glasses where id= '" + (((DataRowView)bindingsources.Current).Row[9].ToString()) + "'");
dataadapter.Update(dataset.Tables["Glasses"]);
dataset.AcceptChanges();
推荐答案
试试这个:
Try this:
string deletestr = "delete from Glasses where id= '" +
(((DataRowView)bindingsources.Current).Row[9].ToString()) + "'";
using (SqlCommand sqlCmd = new SqlCommand(deletestr, SqlConnction))
{
try
{
SqlConnction.Open();
sqlCmd.ExecuteNonQuery();
SqlConnction.Close();
}
catch (Exception)
{
//show error
}
}
检查值如下:
Check the value as the follows:
string value_ID = ((DataRowView)bindingsources.Current).Row[9].ToString();
我认为价值不会是你想要的id值。
另一种解决方案是,如果从删除脚本中删除单引号。
I think the value won't be the id value what you are looking for.
The other solution can be if you delete the single quotes from your delete script.
这篇关于从datagridview中删除记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文