// create a new DataSet object and load data into it DataSet dataSet = new DataSet(); dataSet.ReadXml("data.xml"); // modify some data in the DataSet dataSet.Tables[0].Rows[0]["Name"] = "John Doe"; dataSet.Tables[1].Rows[1].Delete(); // get the changes made to the DataSet DataSet changes = dataSet.GetChanges(); // print the changes if (changes != null) { foreach (DataTable table in changes.Tables) { Console.WriteLine("Changes in table {0}:", table.TableName); foreach (DataRow row in table.Rows) { Console.WriteLine(row.RowState.ToString() + ": " + row[0].ToString()); } } }
// create a new DataSet object and load data into it DataSet dataSet = new DataSet(); dataSet.ReadXml("data.xml"); // modify some data in the DataSet dataSet.Tables[0].Rows[0]["Name"] = "John Doe"; dataSet.Tables[1].Rows[1].Delete(); // apply the changes to the original DataSet dataSet.AcceptChanges(); // get the changes made to the DataSet since the last AcceptChanges call DataSet changes = dataSet.GetChanges(); // print the changes if (changes != null) { foreach (DataTable table in changes.Tables) { Console.WriteLine("Changes in table {0}:", table.TableName); foreach (DataRow row in table.Rows) { Console.WriteLine(row.RowState.ToString() + ": " + row[0].ToString()); } } }This example is similar to the first one, but it applies the changes to the original DataSet by calling AcceptChanges() before calling GetChanges(). This means that only the changes made since the last call to AcceptChanges() will be returned by GetChanges(). The System.Data package library provides the DataSet class and its associated methods.
public GetChanges ( ) : |
||
return |