in chapter 9,the book said the event of rowchanging occurred before using acceptchanges,the event of rowchanged occurred after using acceptchanges.but in the example(update-check-errors.aspx):
Code:
objDataSet.AcceptChanges();
// now set up event handler to react to changes to the rows in the table
DataTable objTable = objDataSet.Tables["Books"];
objTable.RowChanged += new DataRowChangeEventHandler(OnRowChanged);
// now change some records in the Books table
objTable.Rows[0]["Title"] = "Amateur Theatricals for Windows 2000";
objTable.Rows[2]["PublicationDate"] = new DateTime(2001, 2, 11);
// declare a variable to hold a DataView object
DataView objDataView;
// get DataView and set to show only modified rows
objDataView = objDataSet.Tables[0].DefaultView;
objDataView.RowStateFilter = (DataViewRowState)DataRowState.Modified;
// display the contents of the modified rows
dgrResult.DataSource = objDataView;
dgrResult.DataBind();
....
void OnRowChanged(Object objSender, DataRowChangeEventArgs objArgs)
in the above,after changing the datatable,we didn't use acceptchanges,but the event of OnRowChanged occurred after using acceptchanges.
In my opinion,the correct code should be:
Code:
objDataSet.AcceptChanges();
// now set up event handler to react to changes to the rows in the table
DataTable objTable = objDataSet.Tables["Books"];
objTable.RowChanged += new DataRowChangeEventHandler(OnRowChanged);
// now change some records in the Books table
objTable.Rows[0]["Title"] = "Amateur Theatricals for Windows 2000";
objTable.Rows[2]["PublicationDate"] = new DateTime(2001, 2, 11);
objTable.acceptchanges()//this must be needed
// declare a variable to hold a DataView object
DataView objDataView;
// get DataView and set to show only modified rows
objDataView = objDataSet.Tables[0].DefaultView;
objDataView.RowStateFilter = (DataViewRowState)DataRowState.unchanged;
// display the contents of the modified rows
dgrResult.DataSource = objDataView;
dgrResult.DataBind();
....
void OnRowChanged(Object objSender, DataRowChangeEventArgs objArgs)
poor EngLish,sorry!