O'Reilly logo

Microsoft® Visual Basic® .NET Programmer's Cookbook by Matthew MacDonald

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

Use a Transaction with the DataAdapter

Problem

You want to ensure that DataAdapter changes are committed or rolled back as a whole.

Solution

Create a Transaction object, and assign it the DataAdapter commands that are used for deleting, updating, and inserting records.

Discussion

The DataAdapter does not expose a Transaction property. However, the Command objects that the DataAdapter uses do provide this property. The following application shows how you can ensure that all commands in a DataAdapter update operation are grouped into a single transaction:

Dim Con As New SqlConnection(ConnectionString) Dim CmdSelect As New SqlCommand("SELECT * FROM Shippers", Con) Dim Ds As New DataSet() Dim Adapter As New SqlDataAdapter(CmdSelect) ' (Define the custom ...

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