zoukankan      html  css  js  c++  java
  • C#使用事务

            

             /// <summary>
            /// 执行多条SQL语句,实现数据库事务。
            /// </summary>
            /// <param name="SQLStringList">多条SQL语句</param>  
            public static int ExecuteSqlTran(List<String> SQLStringList)
            {
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    connection.Open();
                    SqlCommand cmd = new SqlCommand();
                    cmd.Connection = connection;
                    SqlTransaction tx = connection.BeginTransaction();
                    cmd.Transaction = tx;
                    try
                    {
                        int count = 0;
                        for (int n = 0; n < SQLStringList.Count; n++)
                        {
                            string strsql = SQLStringList[n];
                            if (strsql.Trim().Length > 1)
                            {
                                cmd.CommandText = strsql;
                                count += cmd.ExecuteNonQuery();
                            }
                        }
                        tx.Commit();
                        return count;
                    }
                    catch
                    {
                        tx.Rollback();
                        return 0;
                    }
                    finally
                    {
                        cmd.Dispose();
                        connection.Close();
                    }
                }
            }

  • 相关阅读:
    yum clean all大坑解决
    RHEL 7 “There are no enabled repos” 的解决方法
    exportfs命令 – 管理NFS服务器共享的文件系统
    Linux放大缩小字体的快捷键
    chcon命令详解
    通过配置hosts.allow和hosts.deny文件允许或禁止ssh或telnet操作
    安装RHEL7配置本地yum源 -- yum不能安装时,在本地安装,亲测成功
    块存储、文件存储、对象存储意义及差异
    在Windows Server 2012 R2域环境中禁用(取消)密码复杂策略
    bat脚本静默安装软件示例
  • 原文地址:https://www.cnblogs.com/paste/p/1969982.html
Copyright © 2011-2022 走看看