Exemplo n.º 1
0
        /// <summary>
        /// ExecuteNonQueryAsync
        /// </summary>
        /// <param name="commandText">SQL语句</param>
        /// <param name="commandParameters">参数集合</param>
        /// <param name="transaction">不为空时,使用指定的事务处理;为空时,创建新的连接处理</param>
        /// <returns>受影响行数</returns>
        public static async Task<int> ExecuteNonQueryAsync(string commandText, SqlParameter[] commandParameters, DBTransaction transaction = null)
        {
            int result = 0;

            if (transaction != null)
            {
                result = await AsyncSQLHelper.ExecuteNonQueryAsync(transaction.SqlTransaction, CommandType.Text, commandText, commandParameters);
            }
            else
            {
                result = await AsyncSQLHelper.ExecuteNonQueryAsync(SqlConnectionString, CommandType.Text, commandText, commandParameters);
            }

            return result;
        }
Exemplo n.º 2
0
        //------Extend Methods----------

        #region 事务处理

        /// <summary>
        /// 获取事务支持的对象<para />
        /// 成功执行的最后,请调用MarkSuccess(),事务结束前会自动Commit;
        /// 发生错误或者不显式MarkSuccess()的情况下,均会自动Rollback所有修改;
        /// </summary>
        /// <param name="IsolationLevel">隔离等级</param>
        public static DBTransaction CreateTransaction(IsolationLevel IsolationLevel)
        {
            DBTransaction result = new DBTransaction(IsolationLevel);

            result.Init(SqlConnectionString);

            if (result.IsInitialize == false)
                throw new InvalidOperationException("Create transaction faild.");

            return result;
        }
Exemplo n.º 3
0
        /// <summary>
        /// 查询,返回单一结果
        /// </summary>
        /// <param name="commandText">SQL语句</param>
        /// <param name="commandParameters">参数集合</param>
        /// <param name="transaction">不为空时,使用指定的事务处理;为空时,创建新的连接处理</param>
        /// <returns>单一结果</returns>
        public static object ExecuteScalar(string commandText, SqlParameter[] commandParameters, DBTransaction transaction = null)
        {
            object result = null;

            if (transaction != null)
            {
                result = SyncSQLHelper.ExecuteScalar(transaction.SqlTransaction, CommandType.Text, commandText, commandParameters);
            }
            else
            {
                result = SyncSQLHelper.ExecuteScalar(SqlConnectionString, CommandType.Text, commandText, commandParameters);
            }

            return result;
        }
Exemplo n.º 4
0
        /// <summary>
        /// 查询,返回DataTable结果集
        /// </summary>
        /// <param name="commandText">SQL语句</param>
        /// <param name="commandParameters">参数集合</param>
        /// <param name="transaction">不为空时,使用指定的事务处理;为空时,创建新的连接处理</param>
        /// <returns>DataTable结果集</returns>
        public static async Task<DataTable> ExecuteDataTableAsync(string commandText, SqlParameter[] commandParameters, DBTransaction transaction = null)
        {
            DataSet ds = null;

            if (transaction != null)
            {
                ds = await Task.Run<DataSet>(() => AsyncSQLHelper.ExecuteDataSet(transaction.SqlTransaction, CommandType.Text, commandText, commandParameters));
            }
            else
            {
                ds = await Task.Run<DataSet>(() => AsyncSQLHelper.ExecuteDataSet(SqlConnectionString, CommandType.Text, commandText, commandParameters));
            }

            //返回结果
            if (ds == null || ds.Tables == null || ds.Tables.Count <= 0)
                return null;
            return ds.Tables[0];
        }
Exemplo n.º 5
0
        /// <summary>
        /// 查询,返回DataTable结果集
        /// </summary>
        /// <param name="commandText">SQL语句</param>
        /// <param name="commandParameters">参数集合</param>
        /// <param name="transaction">不为空时,使用指定的事务处理;为空时,创建新的连接处理</param>
        /// <returns>DataTable结果集</returns>
        public static DataTable ExecuteDataTable(string commandText, SqlParameter[] commandParameters, DBTransaction transaction = null)
        {
            DataSet ds = null;

            if (transaction != null)
            {
                ds = SyncSQLHelper.ExecuteDataset(transaction.SqlTransaction, CommandType.Text, commandText, commandParameters);
            }
            else
            {
                ds = SyncSQLHelper.ExecuteDataset(SqlConnectionString, CommandType.Text, commandText, commandParameters);
            }

            //返回结果
            if (ds == null || ds.Tables == null || ds.Tables.Count <= 0)
                return null;
            return ds.Tables[0];
        }
Exemplo n.º 6
0
        /// <summary>
        /// 查询,返回DataSet结果集
        /// </summary>
        /// <param name="commandText">SQL语句</param>
        /// <param name="commandParameters">参数集合</param>
        /// <param name="transaction">不为空时,使用指定的事务处理;为空时,创建新的连接处理</param>
        /// <returns>DataSet结果集</returns>
        public static async Task<DataSet> ExecuteDataSetAsync(string commandText, SqlParameter[] commandParameters, DBTransaction transaction = null)
        {
            DataSet ds = null;

            if (transaction != null)
            {
                ds = await Task.Run<DataSet>(() => AsyncSQLHelper.ExecuteDataSet(transaction.SqlTransaction, CommandType.Text, commandText, commandParameters));
            }
            else
            {
                ds = await Task.Run<DataSet>(() => AsyncSQLHelper.ExecuteDataSet(SqlConnectionString, CommandType.Text, commandText, commandParameters));
            }

            //返回结果
            return ds;
        }
Exemplo n.º 7
0
        //------Database Operate Methods------

        #region 查询,返回DataSet结果集

        /// <summary>
        /// 查询,返回DataSet结果集
        /// </summary>
        /// <param name="commandText">SQL语句</param>
        /// <param name="commandParameters">参数集合</param>
        /// <param name="transaction">不为空时,使用指定的事务处理;为空时,创建新的连接处理</param>
        /// <returns>DataSet结果集</returns>
        public static DataSet ExecuteDataSet(string commandText, SqlParameter[] commandParameters, DBTransaction transaction = null)
        {
            DataSet ds = null;

            if (transaction != null)
            {
                ds = SyncSQLHelper.ExecuteDataset(transaction.SqlTransaction, CommandType.Text, commandText, commandParameters);
            }
            else
            {
                ds = SyncSQLHelper.ExecuteDataset(SqlConnectionString, CommandType.Text, commandText, commandParameters);
            }

            //返回结果
            return ds;
        }