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 <code>Orders</code> table)
Delete parent records (in this case, delete records from the <code>Customers</code> table)
Insert parent records (in this case, insert records in the <code>Customers</code> table)
Insert child records (in this case, insert records in the <code>Orders</code> table)
版权
作者:灵动生活 郝宪玮
如果你认为此文章有用,请点击底端的【推荐】让其他人也了解此文章,
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。