In Chapter 4, we learned about the ADO.NET SqlTransaction class. You can use a SqlTransaction object to group the results of multiple queries on a connection as a single unit of work.
Let’s say that your database contains banking information. You can transfer money from a savings account to a checking account by executing the following two queries:
UPDATE Savings SET BalanceDue = BalanceDue – 100 WHERE AccountID = 17 UPDATE Checking SET BalanceDue = BalanceDue + 100 WHERE AccountID = 17
To make sure you can group the two changes into a single unit of work that you can commit or roll back, you can create a new SqlTransaction object before executing the queries. If an error occurs or one of the queries doesn’t ...