zoukankan      html  css  js  c++  java
  • 数据库操作中使用事务进行提速

     //执行多条语句,实现事务。

            public  void ExecuteSqlTran(ArrayList SQLStringList)
            {
             
                SqlConnection cn = this.getcon();
                cn.Open();
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = cn;
                SqlTransaction tx = cn.BeginTransaction();
                cmd.Transaction = tx;
                try
                {
                    for (int i = 0; i < SQLStringList.Count; i++)
                    {
                        string strSQL = SQLStringList[i].ToString();
                        if (strSQL.Trim().Length > 1)
                        {
                            cmd.CommandText = strSQL;
                            cmd.ExecuteNonQuery();
                        }
                    }
                    tx.Commit();
                }
                catch (System.Data.SqlClient.SqlException e)
                {
                    tx.Rollback();
                    throw new Exception(e.Message);
                }

            }

  • 相关阅读:
    玲珑oj 1129 ST
    HDU 3397 线段树区间修改
    bzoj 1798 双标记区间修改线段树
    HDU 4417 BIT or ST
    HDU 2492 BIT/逆序数/排列组合
    uva 12086 线段树or树状数组练习
    cf 833 A 数论
    wcf的DataContractAttribute与DataMenmberAttribute
    wcf服务查看工具
    git学习-综合性文章
  • 原文地址:https://www.cnblogs.com/quietwalk/p/1722360.html
Copyright © 2011-2022 走看看