From:
http://blog.9cbs.net/ycl111/
The transaction is a set of database operations for a set of logical work units, although there may be errors in the system, but transactions will control and maintain consistency and integrity of each database. If there is no error during the transaction, all modifications in the transaction will be part of the database. If an error is encountered, it will not make any modifications for the database.
For example, in a bank application, if the fund is transferred from an account to another account, a certain amount will be recorded in a account of an account, and the same amount is recorded in another account. Since the computer may fail due to power outages, network interrupts, it is possible to update a row in a table, but no rows in the relevant table. If the database supports the transaction, you can form a transaction to prevent the database from inconsistent due to these events.
In ADO.NET, you can use Connection and Transaction objects to control your transactions. To perform a transaction, do the following:
Call the Begintractions method of the Connection object to mark the beginning of the transaction. BeGintrarsAction returns a reference to Transaction. Please keep this reference to assign it to Command registered in your transaction. Assign the Transaction object to the transaction property of the Command to be executed. If you execute your Command via an active Transaction object, the Transaction object has not been assigned to the Transaction property of Command, the exception will be triggered. Execute the required command. Call the CommT method of the Transaction object to complete the transaction, or call the Rollback method to cancel the transaction. The following code example uses the ADO.NET on Microsoft? SQL Server to demonstrate transaction logic.