Ejemplo n.º 1
0
        /// <summary>
        /// Executes a storedproc and returns a SqlDataTable.
        /// </summary>
        /// <param name="spName"></param>
        /// <param name="inParams"></param>
        /// <returns></returns>
        public DataTable ExecuteDataTable(string spName, params object[] inParams)
        {
            // TODO: check connection state.
            // Get the input parameters.
            SqlParameter[] inputParams = GetInputParameters(inParams);

            // Retrieve the parameter list using the given storedproc name and
            // the wonderful SqlParamCache.
            SqlParameter[] actualParams = SqlParamCache.GetSpParameterSet(
                m_connection,
                spName, true);

            // Now, check if the given input parameters is valid or not.
            CheckInputParameters(inputParams, actualParams);

            // Now the input-parameters-problem was checked and done.
            InitCommand();

            m_command.CommandText = spName;
            m_command.CommandType = CommandType.StoredProcedure;

            PrepareCommandParameters(m_command, inputParams, actualParams);

            // Create a new dataset.
            SqlDataAdapter da = new SqlDataAdapter(m_command);
            DataSet        ds = new DataSet();

            //fill the DataSet using default values for DataTable names, etc.
            da.Fill(ds);

            return(ds.Tables[0]);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Execute a storedproc and return a data adapter.
        /// </summary>
        /// <param name="spName"></param>
        /// <param name="inParams array"></param>
        /// <returns>
        /// SqlDataAdapter
        /// </returns>
        /// Created by : Truong Hoang Uyen
        /// Date : Jun 04, 2003
        public SqlDataAdapter ExecuteAdapter(string spName, params object[] inParams)
        {
            // TODO: check connection state.
            // Get the input parameters.
            SqlParameter[] inputParams = GetInputParameters(inParams);

            // Retrieve the parameter list using the given storedproc name and
            // the wonderful SqlParamCache.
            SqlParameter[] actualParams = SqlParamCache.GetSpParameterSet(
                m_connection,
                spName, true);

            // Now, check if the given input parameters is valid or not.
            CheckInputParameters(inputParams, actualParams);

            // Now the input-parameters-problem was checked and done.
            InitCommand();

            m_command.CommandText    = spName;
            m_command.CommandType    = CommandType.StoredProcedure;
            m_command.CommandTimeout = 7200;
            PrepareCommandParameters(m_command, inputParams, actualParams);

            SqlDataAdapter da = new SqlDataAdapter(m_command);

            return(da);
        }