本文介绍了在asp.net保存方法中使用Rollback的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将Rollback用于以下方法。我之前没有使用begin transaction和rollback。预谢感谢帮助。



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();
             }
         }

推荐答案


这篇关于在asp.net保存方法中使用Rollback的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 13:19