
Code
private void customersBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
UpdateData();
}
private void UpdateData()
{
this.Validate();
this.customersBindingSource.EndEdit();
this.ordersBindingSource.EndEdit();
using (System.Transactions.TransactionScope updateTransaction =
new System.Transactions.TransactionScope())
{
DeleteOrders();
DeleteCustomers();
AddNewCustomers();
AddNewOrders();
updateTransaction.Complete();
northwindDataSet.AcceptChanges();
}
}
The order for reconciling changes to related data is as follows:
-
Delete child records (in this case, delete records from the Orders
table)
-
Delete parent records (in this case, delete records from the Customers
table)
-
Insert parent records (in this case, insert records in the Customers
table)
-
Insert child records (in this case, insert records in the Orders
table)