Transactions with Asp.Net

Read about how to create a database transaction with Asp.Net.

SqlTransaction trans = null;
try
{
conn = new SqlConnection ( . . . );
conn.Open();
trans = conn.BeginTransaction();
cmd = new Command();
cmd.Connenction = conn;
cmd.Transaction = trans;
cmd.ExecuteNonQuery();

}
catch(Exception objException)
{
if(trans!=null)
trans.Rollback();
}
finally
{
if(conn!=null)
conn.Close();
}

By Jesper Lind
1