O'Reilly logo

Programming Microsoft® ADO.NET 2.0 Core Reference, 2nd Edition by David Sceppa

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

Submitting Updates in SqlTransactions

What if you want to submit all your updates as a single unit of work so that either all the updates succeed or none of them does? You could create a SqlTransaction for your SqlConnection and wrap the updates in that transaction. However, the SqlDataAdapter does not expose a Transaction property. What to do?

Remember that the SqlDataAdapter does not actually submit the updates. It simply hands the work off to the SqlCommand objects in its UpdateCommand, InsertCommand, and DeleteCommand properties. The SqlCommand object exposes a Transaction property, so to submit the changes using the SqlDataAdapter, you must set the Transaction property of the SqlCommand objects that the SqlDataAdapter will use.

The following ...

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