文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>C# 事务

C# 事务

时间:2011-04-19  来源:希望你喜欢

/// <summary>
        /// 在一个事务中执行一组任务
        /// </summary>
        /// <param name="dataAccesses">一组任务</param>
        /// <returns>成功返回 true ; 否则 false</returns>
        public static bool BatchExecuteNonQuery(params DataAccess[] dataAccesses)
        {
            bool Success = false;
            DbConnection connection = dataAccesses[0].Connection;

            if (connection.State != ConnectionState.Open)
                connection.Open();

            DbTransaction trans = connection.BeginTransaction(IsolationLevel.ReadCommitted);

            try
            {
                foreach (DataAccess dataAccess in dataAccesses)
                {
                    dataAccess.Command.Connection = connection;
                    dataAccess.Command.Transaction = trans;

                    dataAccess.Command.ExecuteNonQuery();
                }

                trans.Commit();
                Success = true;
            }
            catch (Exception e)
            {
                trans.Rollback();
                throw e;
            }
            finally
            {
                dataAccesses[0].Connection.Close();
            }

            return Success;
        }

相关阅读 更多 +
排行榜 更多 +
找茬脑洞的世界安卓版

找茬脑洞的世界安卓版

休闲益智 下载
滑板英雄跑酷2手游

滑板英雄跑酷2手游

休闲益智 下载
披萨对对看下载

披萨对对看下载

休闲益智 下载