1
Answer

About handle transaction

Photo of Ganesh Bisht

Ganesh Bisht

13y
1.2k
1
How we handle transactions in asp.net?

Answers (1)

0
Photo of Senthilkumar
NA 15.2k 2.4m 13y

You can use the following.

//Begin Transaction
SqlTransaction trans = conn.BeginTransaction("RemoveProducts");

try

{
//Delete Product
SqlCommand cmd = new SqlCommand("", conn, trans);
cmd.CommandText = "Delete from Products where ID=5";
cmd.ExecuteNonQuery();

trans.Commit();

}
catch(SqlException sqlex)
{
        transs.RollBack();
}