System.Transactions best for SQL 2005!!
In .net framework 2.0, a new namespace has been introduced, called System.Transactions. I have been able to greatly reduce my code for doing SQL transaction.
The code goes like this.
Using System.Transactions;
using (TransactionScope scope = new TransactionScope())
{
using(SqlConnection conn = new SqlConnection(connString))
{
SqlCommand cmdInsert = conn.CreateCommand();
cmdInsert.CommandText="INSERT INTO...";
SqlCommand cmdUpdate = conn.CreateCommand();
cmdUpdate.CommandText="UPDATE .....";
cmdInsert.ExecuteNonQuery();
cmdUpdate.ExecuteNonQuery();
}
scope.Complete();
}
Whenever I've to work for SQL 2005, I don't miss to use TransactionScope. Its short and simple.