Transactions and ADO.NET

The ADO.NET Connection object is used to work with transactions. As you'll see in the next few sections, the Connection object is used to initiate the transaction. Any command objects that need to enlist in the transaction are then assigned to the transaction. The transaction object itself is used to save, roll back, and perform other actions on the transaction.

Starting a Transaction

In ADO.NET, you can start a database transaction by calling the BeginTransaction() method of the Connection object, as seen in Listing 18.1.

Listing 18.1. Starting a New Transaction
 'Create Connection Dim conn as SqlConnection = new SqlConnection("Data Source=(local);" + "Initial Catalog=northwind;UID=sa;PWD=;") 'Create Command Dim cmd ...

Get Sams Teach Yourself ADO.NET in 24 Hours now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.