Click here to Skip to main content
15,921,959 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to use Rollback to the following method. I have not use begin transaction and rollback before. Advance thanks for helping.

try
        {
if (btnConfirm.Text == "Save")
            {
                SqlCommand cmd = new SqlCommand("Smt_Mc_McInformation_Save", cn);
                if (cn.State == ConnectionState.Closed)
                {
                    cn.Open();
                }
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@McAsstNo", txtAssetNo.Text.Trim());
                cmd.Parameters.AddWithValue("@McCode", ddlDescription.SelectedValue);
 cmd.ExecuteNonQuery();
 }
 else
            {
                SqlCommand cmd = new SqlCommand("Smt_Mc_McMachine_Master_Edit", cn);
                if (cn.State == ConnectionState.Closed)
                {
                    cn.Open();
                }
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@McAsstNo", txtAssetNo.Text.Trim());
                cmd.Parameters.AddWithValue("@McModel", txtModel.Text.Trim());
 cmd.ExecuteNonQuery();
 }
        }
        catch (Exception ex)
        {
            throw ex;
        }
         finally
         {
             if (Session["Uid"].ToString() == "ADMIN" || Session["Uid"].ToString() == "admin")
             {
                 LoadGridForAd();
             }
             else
             {
                 LoadGrid();
             }

             ClearText();
             if (cn.State == ConnectionState.Open)
             {
                 cn.Close();
             }
         }
Posted
Updated 25-Nov-14 17:15pm
v3

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900