示例#1
0
        /// <summary>
        /// Creates instance of DataReader for commandText,commandType, active connection, active
        /// transaction and optional Parameters.
        /// </summary>
        ///
        /// <remarks>   Asim Naeem, 7/20/2017. </remarks>
        ///
        /// <param name="commandText">  Open Sql Statement or Procedure Name. </param>
        /// <param name="commandType">  CommandType for Text or StoredProcedure (1 or 4) </param>
        /// <param name="connection">   Active Connection Object. </param>
        /// <param name="transaction">  Active Transaction Object. </param>
        /// <param name="aParams">      (Optional) Collection of Optional Parameters. </param>
        ///
        /// <returns>   An IDataReader. </returns>


        private IDataReader ExecuteDataReader(string commandText, CommandType commandType, IDbConnection connection, IDbTransaction transaction, DBParameter[] aParams = null)
        {
            IDataReader dataReader = null;

            try
            {
                using (IDbCommand dbCommand = CreateCommand(commandText, commandType))
                {
                    if (aParams != null)
                    {
                        HelperUtility.AddParameters(dbCommand, aParams, DBProvider);
                    }
                    dbCommand.Transaction = transaction;
                    dbCommand.Connection  = connection;
                    if (connection.State != ConnectionState.Open)
                    {
                        connection.Open();
                    }
                    dataReader = dbCommand.ExecuteReader(CommandBehavior.CloseConnection);
                }
            }
            catch (Exception exc)
            {
                Logger.ILogger.Fatal(exc);
                throw;
            }
            return(dataReader);
        }
示例#2
0
文件: IDatabase.cs 项目: achhee/DAL
        /// <summary>
        /// Creates Command Instance For active DBProvider for CommandText, CommandType and Optional
        /// parameter.
        /// </summary>
        ///
        /// <remarks>   Asim Naeem, 7/20/2017. </remarks>
        ///
        /// <param name="commandText">  Open Sql Statement or Procedure Name. </param>
        /// <param name="commandType">  CommandType for Text or StoredProcedure (1 or 4) </param>
        /// <param name="aParams">      (Optional) Collection of Optional parameter. </param>
        ///
        /// <returns>   Active Command object. </returns>


        public virtual IDbCommand CreateCommand(string commandText, CommandType commandType, DBParameter[] aParams = null)
        {
            IDbCommand command = CreateCommand();

            command.CommandText = commandText;
            command.CommandType = commandType;
            if (aParams != null)
            {
                HelperUtility.AddParameters(command, aParams, DBProvider);
            }
            ILogger.Info(commandText);
            return(command);
        }