Transaction in .net By:Tanuj Kumar

share your conscience

Transaction Example in .Net Program:

//first of all take button click event
button click()
   {
//create SqlConnection class object      
SqlConnection con = new SqlConnection("Connnection string");
      SqlTransaction transaction;
//open connection
       con.Open();
//begin transaction
      transaction = con.BeginTransaction();
      try 
      {
         new SqlCommand("INSERT INTO Transaction " +
            "(Text) VALUES ('Row1');", con, transaction)
            .ExecuteNonQuery();
         new SqlCommand("INSERT INTO Transaction " +
            "(Text) VALUES ('Row2');", con, transaction)
            .ExecuteNonQuery();
         new SqlCommand("INSERT INTO transaction2 VALUES " +
            "('Die', 'Die', 'Die');", con, transaction)
            .ExecuteNonQuery();
         transaction.Commit();
      } 
      catch (SqlException sqlError) 
      {
         transaction.Rollback();
      }
      con.Close();
   }



Posted By:Tanuj Kumar 
On:Shareyourconscience

Transaction in .net By:Tanuj Kumar Transaction in .net By:Tanuj Kumar Reviewed by Tanuj on 11:54:00 pm Rating: 5

No comments:

Powered by Blogger.