Monday, 14 January 2013

SQL Transaction In C#,ASP.Net

 Transaction In C#,ASP.Net
 



SqlTransaction transaction;
con.Open();
transaction = con.BeginTransaction();
try
{
for (int i = 0; i < dtTemp.Rows.Count; i++)
{
SqlCommand cmd = new SqlCommand("insert command....", con,transaction);
cmd.ExecuteNonQuery();
}
transaction.Commit();
}

catch (Exception Error)
{


}

In above Part the only thing you have to care about is

SqlTransaction transaction;
con.Open();
transaction = con.BeginTransaction();
try {
  SqlCommand cmd = new SqlCommand("insert command....", con,transaction);
cmd.ExecuteNonQuery();
transaction.Commit();                    //whenever you call commit it means now finaly
                                                       //all execution will take place else rollback to catch
}
catch
{
  transaction.Rollback(); 

No comments:

Post a Comment

Print Only Grid View in ASP.net

ASP.net How to Print Only GridView < div id ="gridviewDiv" >   < asp:GridView ID ="gridViewToPri...