同样的方法添加时,数据库却更新了.什么原因??
求高手指点

解决方案 »

  1.   

    代码如下
    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();
                            
            }
      

  2.   

    在Page_Load事件中加
    if (!IsPostBack)
    {
      //绑定数据
     }
      

  3.   

    DataAdapter.Update
    这个我用了啊
      

  4.   

    改为
    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();
                            
            }
      

  5.   

    DataSet.AcceptChanges(); 换到后面才行
      

  6.   

    这样也不行
    错误提示为Dynamic SQL generation for the DeleteCommand is not supported against a SelectCommand that does not return any key column information.
      

  7.   

    如果是点击按钮后没有反应,在这段代码内下断点看程序执行这段代码没,如果没执行可能是事件处理没有通知系统,在private void InitializeComponent()内加上类似this.btnpdate.Click += new System.EventHandler(this.btnUpdate_Click);的代码
      

  8.   

    添加
    this.button3.Click += new System.EventHandler(this.button3_Click);的代码
    后,运行到
    button3就出错
      

  9.   

    还有什么问题? 错误信息是什么还有前面有人指出了,在update前,不能执行DataSet.AcceptChanges(),不然的话rowstate都变成unchanged的了 
      

  10.   

    没有错误,就是后台数据库没有更新DataSet.AcceptChanges(); 换到后面时就出错了错误信息为
    Dynamic SQL generation for the DeleteCommand is not supported against a SelectCommand that does not return any key column information.
      

  11.   

    把你要更新的表设立一个主键,然后把DataAdapter这个控件重新添加
      

  12.   

    1  DataSet.AcceptChanges(); 一定不能在update的前面,要不要表不会更新。
    2 表中一定要有主键,添加完之后如果你这个dataAdapter是使用程序中的工具生成的,重新生成一遍