C#如何实现修改dataGrid里的值同时数据里的值也修改,我写的只能对点击的当前行修改,如何能实现对任意一行的修改同时数据库里对应的也能修改。
string sql;
conn.Open();
comm.Connection=conn;
sql="update yqr set wwxm='"+rs.Tables["yqr"].Rows[this.dataGrid2.CurrentRowIndex]["wwxm"].ToString()+"' where id="+rs.Tables["yqr"].Rows[this.dataGrid2.CurrentRowIndex]["id"].ToString();
this.DataAdapter1.UpdateCommand=new System.Data.OleDb.OleDbCommand(sql,this.conn);
this.DataAdapter1.Update(rs,"yqr");
conn.Close();

解决方案 »

  1.   

    ds.Accept();--数据集接受修改
    da.update();--适配器返回修改数据库
      

  2.   

    记住:在修改数据库内容之前不要执行ds.Accept();
    da.update()后再ds.AcceptChanges();
      

  3.   

    private void AcceptChanges()
    {
       DataSet myDataSet;
       myDataSet = new DataSet();   // Not shown: methods to fill the DataSet with data.
       DataTable t;
       t = myDataSet.Tables["Suppliers"];   // Add a DataRow to a table.
       DataRow myRow;
       myRow = t.NewRow();
       myRow["CompanyID"] = "NWTRADECO";
       myRow["CompanyName"] = "NortWest Trade Company";   // Add the row.
       t.Rows.Add( myRow );   // Calling AcceptChanges on the DataSet causes AcceptChanges to be
       // called on all subordinate objects.
       myDataSet.AcceptChanges();
    }
      

  4.   

    你的dataadapter的其他更新语句写的不合理,你用CommandBuilder来产生效果会更好。