zoukankan      html  css  js  c++  java
  • .net事务使用实例

     

     #region 批量处理Sql
            /// <summary>
            /// 批量处理Sql
            /// </summary>
            /// <param name="Array_Sql"></param>
            /// <returns></returns>
            public static bool FileInsertToData(string[] Array_Sql)
            {
                bool  Result= true;

                SqlConnection sqlConn = new SqlConnection(strConn);
                SqlCommand Comm = sqlConn.CreateCommand();
                SqlTransaction myTrans;

                myTrans = sqlConn.BeginTransaction();

                Comm.Connection = sqlConn;
                Comm.Transaction = myTrans;
                Comm.CommandType = CommandType.Text;
                sqlConn.Open();
                try
                {
                    for (int i = 0; i < Array_Sql.Length; i++)
                    {
                        Comm.CommandText = Array_Sql[i].ToString();
                        Comm.ExecuteNonQuery();
                    }
                    myTrans.Commit();//事务提交
                    Result = true;
                }
                catch (Exception ex)
                {
                    myTrans.Rollback();//事务回滚
                    Result = false;
                }
                finally
                {
                    sqlConn.Close();
                    Comm.Dispose();
                }

                return Result;

            }

            #endregion

  • 相关阅读:
    Google Chrome 自定义协议(PROTOCOL)问题的处理
    C# 6.0/7.0 的新特性
    MySQL 5.7.18 压缩包版配置记录
    nginx.conf文件内容详解
    博客添加动态动漫妹子
    TypeScript 3.8beta版
    微信浏览器H5开发常见的坑
    Babel7知识梳理
    雅虎前端优化35条规则
    webpack
  • 原文地址:https://www.cnblogs.com/moss_tan_jun/p/1809065.html
Copyright © 2011-2022 走看看