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();
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();
da.update();--适配器返回修改数据库
da.update()后再ds.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();
}