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

Get Programming Microsoft® ADO.NET 2.0 Core Reference, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.