O'Reilly logo

Sams Teach Yourself ADO.NET in 24 Hours by Paul Bertucci, Jason Lefebvre

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required