C# DATABIND ADAPTER TRANSACTION相关

来源:百度知道 编辑:UC知道 时间:2024/05/27 14:34:05
Adding Transaction Support to a Table Adapter
If you want to execute multiple queries through a table adapter within the scope of a single transaction, you have a couple of options. You can use the TRansactionScope class from the new System.Transactions namespace to execute the queries within a single transaction scope:

public void ExecuteTransaction(CustomersDataSet.CustomersDataTable
customers)
{

CustomersTableAdapter adapter = new CustomersTableAdapter();
// Start the transaction
using (TransactionScope scope = new TransactionScope())
{
// Save any changes currently in the data table
adapter.Update(customers) // First query
customers[0].Phone = "030-0074321"; // make a change
adapter.Update(customers); // Second query
scope.Complete(); // Commits the transaction
}
}

However, doing this may result in this usi

但是,这样做可能会导致本使用分布式事务,并在应用程序的设计不同,这可能比直接使用数据库事务的成本更高的性能。

如果你想对一个管理表适配器直接交易,您可以通过增加自己的部分类定义与表适配器为您要修改的项目相同的名称,然后添加一些代码表适配器类,允许客户端建立一个交易将包括通过表适配器执行任何疑问。

如果您添加新的类文件的NorthwindDataAccess类库项目,并添加清单2.6它的代码,CustomersTableAdapter类将扩展至增加功能,即是由一套设计师的类型化数据生成的代码。