业务逻辑层实现事务处理

简介: Codeprivate void customersBindingNavigatorSaveItem_Click(object sender, EventArgs e){    UpdateData();}private void UpdateData(){    this.

 

img_1c53668bcee393edac0d7b3b3daff1ae.gif img_405b18b4b6584ae338e0f6ecaf736533.gif 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)

 

版权

作者:灵动生活 郝宪玮

出处:http://www.cnblogs.com/ywqu

如果你认为此文章有用,请点击底端的【推荐】让其他人也了解此文章,

img_2c313bac282354945ea179a807d7e70d.jpg

本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

 

相关文章
|
5月前
|
存储 设计模式 测试技术
了解三层架构:表示层、业务逻辑层、数据访问层
了解三层架构:表示层、业务逻辑层、数据访问层
322 0
|
2月前
|
测试技术
封装并集中处理业务逻辑
封装并集中处理业务逻辑
12 1
|
11月前
|
关系型数据库 MySQL Java
多数据源事务处理-涉及分布式事务
多数据源事务处理-涉及分布式事务
112 0
|
开发者
数据层设计与开发(数据层工厂类) | 学习笔记
简介:快速学习数据层设计与开发(数据层工厂类)
80 0
数据层设计与开发(数据层工厂类) | 学习笔记
|
项目管理
业务逻辑?
业务逻辑?
135 0
业务逻辑?
|
开发者
待业务层设计与开发(业务层工厂类) | 学习笔记
简介:快速学习待业务层设计与开发(业务层工厂类)
51 0
|
存储 XML 算法
java三层架构:数据访问层、业务逻辑层、表现层
java三层架构:数据访问层、业务逻辑层、表现层
1571 0