文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>.net事务使用实例

.net事务使用实例

时间:2010-08-26  来源:moss_tan_jun

 

 

 #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

 

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载