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

  • 相关阅读:
    react之引用echarts
    vue之生命周期
    算法之冒泡排序
    算法之快速排序
    算法题之统计字符串中出现最多的字母
    使用http-proxy-middleware 代理跨域
    div产生的滚动条返回顶部
    Django实战(18):提交订单
    Django实战(17):ajax !
    Django实战(16):Django+jquery
  • 原文地址:https://www.cnblogs.com/moss_tan_jun/p/1809065.html
Copyright © 2011-2022 走看看