Example #1
0
        /// <summary>
        /// 执行存储过程,返回SqlDataReader ( 注意:调用该方法后,一定要对SqlDataReader进行Close )
        /// </summary>
        /// <param name="storedProcName">存储过程名</param>
        /// <param name="parameters">存储过程参数</param>
        /// <returns>SqlDataReader</returns>
        public SqlDataReader RunProcedure(string storedProcName, IDataParameter[] parameters)
        {
            SqlConnection connection   = Connection;
            SqlDataReader returnReader = null;

            OpenConnection();
            SqlCommand command = (SqlCommand)StoredProcCommandBuilder.BuildQueryCommand(connection, storedProcName, parameters);

            command.CommandType = CommandType.StoredProcedure;
            try
            {
                returnReader = command.ExecuteReader(CommandBehavior.CloseConnection);
            }
            catch (System.Exception ex)
            {
                command.Dispose();
                connection.Close();
            }

            return(returnReader);
        }
Example #2
0
        /// <summary>
        /// 执行存储过程,返回SqlDataReader ( 注意:调用该方法后,一定要对SqlDataReader进行Close )
        /// </summary>
        /// <param name="storedProcName">存储过程名</param>
        /// <param name="parameters">存储过程参数</param>
        /// <returns>SqlDataReader</returns>
        public int RunProcedureRef(string storedProcName, IDataParameter[] parameters)
        {
            SqlConnection connection = Connection;

            OpenConnection();
            SqlCommand command = (SqlCommand)StoredProcCommandBuilder.BuildQueryCommand(connection, storedProcName, parameters);

            try
            {
                return(command.ExecuteNonQuery());
            }
            catch (System.Exception ex)
            {
                connection.Close();
            }
            finally
            {
                command.Dispose();
            }

            return(0);
        }