Using Transactions

Posted on: Fri Jun 27 12:26:12 -0700 2008. Updated on: Thu Sep 04 12:45:26 -0700 2008.
Category: DotNet

It is important to use transactions when inserting or doing a lot of database manipulation. Here is a quick example:

 
 using (TransactionScope scope = new TransactionScope())
            {
                SomeDSTableAdapters.cs_recordsTableAdapter ta = new SomeDSTableAdapters.cs_recordsTableAdapter();
                ta.Connection.ConnectionString = _connectionString;
                ta.DeleteAllRecords();

                ta.Update(ds);

                scope.Complete();
            }

To Enable transactions go to "References" (in your project), right click and hit "Add Reference" and scroll down to System.Transactions and hit Ok. Next add the following code to the very top of your cs file:

using System.Transactions;

Comments:

Add a Comment:

simple_captcha.jpg
(human authentication)


Ads

Categories

About

Random foliage

This website is meant to be a reference for ASP Dot Net developers. The entries are a compilation of things I've figured out how to do and that I deem useful to keep of track for future reference. Assumptions: web development with: C Sharp (vb sucks), visual studio 05/08, .net 3.5, meant for programmers. Written by: James Reategui.