The solution to the transaction problem in the strongly typed DataSet mentioned last time is also useful for general transaction solutions
The TransactionScope class provides a simple way in which you can mark a code block as participating in a transaction without interacting with the transaction itself. The transaction scope can automatically select and manage environmental transactions. Because it is easy to use and highly efficient, it is recommended that you use the TransactionScope class when developing a transactional application.
In addition, you do not have to explicitly register a resource with a transaction. Any system.transactions resource Manager, such as SQL Server 2005, can detect the existence of an environment transaction created by that scope and register automatically.
Before using, you should ensure that the MSDTC (Distributed Transaction coordination Processor) service is started:
The following figure:
So, when you do a strongly typed design, you can write code like this:
The steps are as follows:
1 Add (. net2.0) System.Transactions in the project reference
2 Adding a using System.Transactions in the head;
3 Add the following code fragment:
using (System.Transactions.TransactionScope updatetransaction = New System.Transactions.TransactionScope ())
{
Ta. Insertname ("1456789", "456"), " 456 " );
Ta1. InsertName1 (