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

            }

  • 相关阅读:
    数据类型
    表达式
    类型
    go杂货铺
    rest framework
    go 学习之路(三)
    go 学习之路(二)
    文件管理之字符处理命令,打包压缩
    文件管理之文件查找,上传下载,输出重定向
    文本命令之三剑客初探
  • 原文地址:https://www.cnblogs.com/quietwalk/p/1722360.html
Copyright © 2011-2022 走看看