static void Main(string[] args) { DataSet simpleShopDb = new DataSet(); simpleShopDb.ReadXmlSchema(@"D:\ADO.NET\DATA\ShopDbSchema.xml"); simpleShopDb.ReadXml(@"D:\ADO.NET\DATA\ShopDBData.xml"); ShopDB strongedShopDB = new ShopDB(); strongedShopDB.Customers.Merge(simpleShopDb.Tables["Customers"]); strongedShopDB.AcceptChanges(); var selectedCustomer = strongedShopDB.Customers.FindByCustomerNo(1); selectedCustomer.Phone = "New Value"; // Метод GetChanes() получает копию класса DataSet, содержащую все изменения, внесенные после его последней загрузки или после вызова метода AcceptChanges. DataSet datasetWithChanges = strongedShopDB.GetChanges(); ShopDB inst = datasetWithChanges as ShopDB; foreach (DataRow row in datasetWithChanges.Tables["Customers"].Rows) { foreach (DataColumn column in datasetWithChanges.Tables["Customers"].Columns) { Console.WriteLine("{0}: {1}", column.ColumnName, row[column]); } } }
static void Main(string[] args) { var simpleShopDB = new DataSet(); simpleShopDB.ReadXmlSchema(@"C:\Users\HP\Desktop\Test\ShopDbSchema.xml"); simpleShopDB.ReadXml(@"C:\Users\HP\Desktop\Test\ShopDBData.xml"); var strongShopDB = new ShopDB(); strongShopDB.Customers.Merge(simpleShopDB.Tables["Customers"]); strongShopDB.AcceptChanges(); var selectedCustomer = strongShopDB.Customers.FindByCustomerNo(1); selectedCustomer.Phone = "testValue"; DataSet dataSetWithChanges = strongShopDB.GetChanges(); //returns dataset with all the changes made on strongshopdb var instance = dataSetWithChanges as ShopDB; //we can downcast data set to shopdb as shopdb is a dataset foreach (DataRow row in dataSetWithChanges.Tables["Customers"].Rows) { foreach (DataColumn column in dataSetWithChanges.Tables["Customers"].Columns) { Console.WriteLine($"{column.ColumnName}: {row[column]}"); } } Console.ReadKey(); }