zoukankan      html  css  js  c++  java
  • C# 数据回滚

    public  int GetExecteQuery(string strAddSql, string strUpdateSql, string strDelSql)
            {
                SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["GPSP_SQL"]);//实例化数据连接
                //SqlConnection conn = new SqlConnection(CONN_STRING);
                conn.Open();
                SqlCommand command = conn.CreateCommand();
    
                SqlTransaction transaction = null;
                transaction = conn.BeginTransaction();
                command.Connection = conn;
                command.Transaction = transaction;
                int count = 0;
    
                try
                {
                    if (strAddSql != "")
                    {
                        command.CommandText = “insert into A.....”;
                        command.ExecuteNonQuery();
                    }
                    if (strUpdateSql != "")
                    {
                        command.CommandText = “insert into B.....”;
                        count = command.ExecuteNonQuery();
                    }
                    if (strDelSql != "")
                    {
                        command.CommandText = “insert into C.....”;
                        count = command.ExecuteNonQuery();
                    }
                    transaction.Commit();
                }
                catch
                {
    
                    transaction.Rollback();
                }
    
                return count;
            }
  • 相关阅读:
    WebSocket资料
    HTML5新增特性
    CSS3新增选择器
    HTM5基本语法
    HTML语义化
    浏览器内核分类
    Layui表格的单双击处理
    c++ cin读取多行数字
    计算机视觉中关于人脸的一些任务
    python实现NMS和softNMS代码
  • 原文地址:https://www.cnblogs.com/beeone/p/3897555.html
Copyright © 2011-2022 走看看