예제 #1
0
        /// <summary>
        /// Executes the procedure.
        /// </summary>
        /// <returns>A List containing SqlRows or null if the Connection and Command for this procedure are not initialized.</returns>
        /// <exception cref="System.ApplicationException">Thrown if there is an error executing the stored procedure.</exception>
        public List<SqlRow> Execute()
        {
            // Check whether the connection and command are initialized.
            if (Connection != null && Command != null)
            {
                // The List of records to return.
                List<SqlRow> rowList = new List<SqlRow>();

                // The connection and command are initialized.
                try
                {
                    Connection.Open();

                    //Initialize a reader to read the results of the procedure.
                    DbDataReader reader = (DbDataReader)Command.ExecuteReader();

                    // Read all records.
                    while (reader.Read())
                    {
                        // The SqlRow for storing the results of the procedure.
                        SqlRow row = new SqlRow();

                        // Read all fields.
                        for (int i = 0; i < reader.FieldCount; i++)
                        {
                            // The name of the field read.
                            string fieldName = reader.GetName(i);

                            // The value of the field read.
                            Object valueObject = reader[fieldName];

                            // Check if the value of the object is null.
                            if (valueObject != DBNull.Value)
                            {
                                // The value is not null.
                                // Add the value to the row.
                                row.Add(i, fieldName, reader[fieldName]);
                            }
                            else
                            {
                                // The value is null.
                                // Add a null value to the row.
                                row.Add(i, fieldName, null);
                            }
                        }
                        // Add the row the list of rows.
                        rowList.Add(row);
                    }
                    reader.Close();
                    return rowList;
                }
                catch (DbException e)
                {
                    throw new ApplicationException("Error executing " + Name + " stored procedure.", e);
                }
                finally
                {
                    if (Connection != null)
                    {
                        Connection.Close();
                    }
                }
            }
            return null;
        }
예제 #2
0
        /// <summary>
        /// Executes the procedure.
        /// </summary>
        /// <returns>A List containing SqlRows or null if the Connection and Command for this procedure are not initialized.</returns>
        /// <exception cref="System.ApplicationException">Thrown if there is an error executing the stored procedure.</exception>
        public List <SqlRow> Execute()
        {
            // Check whether the connection and command are initialized.
            if (Connection != null && Command != null)
            {
                // The List of records to return.
                List <SqlRow> rowList = new List <SqlRow>();

                // The connection and command are initialized.
                try
                {
                    Connection.Open();

                    //Initialize a reader to read the results of the procedure.
                    DbDataReader reader = (DbDataReader)Command.ExecuteReader();

                    // Read all records.
                    while (reader.Read())
                    {
                        // The SqlRow for storing the results of the procedure.
                        SqlRow row = new SqlRow();

                        // Read all fields.
                        for (int i = 0; i < reader.FieldCount; i++)
                        {
                            // The name of the field read.
                            string fieldName = reader.GetName(i);

                            // The value of the field read.
                            Object valueObject = reader[fieldName];

                            // Check if the value of the object is null.
                            if (valueObject != DBNull.Value)
                            {
                                // The value is not null.
                                // Add the value to the row.
                                row.Add(i, fieldName, reader[fieldName]);
                            }
                            else
                            {
                                // The value is null.
                                // Add a null value to the row.
                                row.Add(i, fieldName, null);
                            }
                        }
                        // Add the row the list of rows.
                        rowList.Add(row);
                    }
                    reader.Close();
                    return(rowList);
                }
                catch (DbException e)
                {
                    throw new ApplicationException("Error executing " + Name + " stored procedure.", e);
                }
                finally
                {
                    if (Connection != null)
                    {
                        Connection.Close();
                    }
                }
            }
            return(null);
        }