求助:用删除按扭删除记录时,用了Update,后台数据库却更新不了 同样的方法添加时,数据库却更新了.什么原因??求高手指点 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 代码如下private void button3_Click(object sender, EventArgs e) { DataRow targetRow = dataTable.Rows[listBox1.SelectedIndex]; dataTable.Rows[listBox1.SelectedIndex].Delete(); DataSet.AcceptChanges(); DataAdapter.Update(DataSet, "book"); Application.DoEvents(); } 在Page_Load事件中加if (!IsPostBack){ //绑定数据 } DataAdapter.Update这个我用了啊 改为private void button3_Click(object sender, EventArgs e) { DataRow targetRow = dataTable.Rows[listBox1.SelectedIndex]; dataTable.Rows[listBox1.SelectedIndex].Delete(); DataAdapter.Update(DataSet, "book"); DataSet.AcceptChanges(); Application.DoEvents(); } DataSet.AcceptChanges(); 换到后面才行 这样也不行错误提示为Dynamic SQL generation for the DeleteCommand is not supported against a SelectCommand that does not return any key column information. 如果是点击按钮后没有反应,在这段代码内下断点看程序执行这段代码没,如果没执行可能是事件处理没有通知系统,在private void InitializeComponent()内加上类似this.btnpdate.Click += new System.EventHandler(this.btnUpdate_Click);的代码 添加this.button3.Click += new System.EventHandler(this.button3_Click);的代码后,运行到button3就出错 还有什么问题? 错误信息是什么还有前面有人指出了,在update前,不能执行DataSet.AcceptChanges(),不然的话rowstate都变成unchanged的了 没有错误,就是后台数据库没有更新DataSet.AcceptChanges(); 换到后面时就出错了错误信息为Dynamic SQL generation for the DeleteCommand is not supported against a SelectCommand that does not return any key column information. 把你要更新的表设立一个主键,然后把DataAdapter这个控件重新添加 1 DataSet.AcceptChanges(); 一定不能在update的前面,要不要表不会更新。2 表中一定要有主键,添加完之后如果你这个dataAdapter是使用程序中的工具生成的,重新生成一遍 .net 网站更新的时候提示到一个更新中的页面 C#复试主要是做什么?成都迈思 字符串的匹配(急呀,大家帮下忙) 再问:FormView怎样获得存储过程的返回值 动态加载控件的布局问题 有谁遇到过这个问题,请进来帮一下啊.真的很着急啊.解决马上给分结贴. dotnetbarmanager 字符串"123"怎么样转为整形呀?高手指点一下呀 為什么在簡體操作系統中建立的form﹐在繁體系統中運行會變形(大小) 用C#怎样做弹出式菜单? GBK码如何写入XML??如何转码以供socket传送用?? BaseStream发生溢出错误
private void button3_Click(object sender, EventArgs e)
{
DataRow targetRow = dataTable.Rows[listBox1.SelectedIndex];
dataTable.Rows[listBox1.SelectedIndex].Delete();
DataSet.AcceptChanges(); DataAdapter.Update(DataSet, "book");
Application.DoEvents();
}
if (!IsPostBack)
{
//绑定数据
}
这个我用了啊
private void button3_Click(object sender, EventArgs e)
{
DataRow targetRow = dataTable.Rows[listBox1.SelectedIndex];
dataTable.Rows[listBox1.SelectedIndex].Delete();
DataAdapter.Update(DataSet, "book");
DataSet.AcceptChanges();
Application.DoEvents();
}
错误提示为Dynamic SQL generation for the DeleteCommand is not supported against a SelectCommand that does not return any key column information.
this.button3.Click += new System.EventHandler(this.button3_Click);的代码
后,运行到
button3就出错
Dynamic SQL generation for the DeleteCommand is not supported against a SelectCommand that does not return any key column information.
2 表中一定要有主键,添加完之后如果你这个dataAdapter是使用程序中的工具生成的,重新生成一遍