Exemple #1
0
        public IEnumerable <ThisYearsDate> SelThisYearsDates()
        {
            int intRC = 0;

            objThisYearsDate = new List <ThisYearsDate>();

            IParameterFactory objParams = new ThisYearsDateParameterFactory();

            System.Data.SqlClient.SqlCommand objCmd = new SqlCommand("pSelThisYearsDates", new ADOConnectionFactory().Connection);
            objCmd.CommandType = CommandType.StoredProcedure;

            objCmd.Parameters.Add(objParams.Parmeters["RC"]);

            try
            {
                objCmd.Connection.Open();
                System.Data.SqlClient.SqlDataReader objDR = objCmd.ExecuteReader();
                while (objDR.Read())
                {
                    ThisYearsDate objTYD = new ThisYearsDate();
                    objTYD.DateID   = (int)objDR["DateID"];
                    objTYD.DateName = (string)objDR["PDateName"];
                    ((List <ThisYearsDate>)objThisYearsDate).Add(objTYD);
                }
                objDR.Close();
                intRC = (int)objParams.Parmeters["RC"].Value;
                if (intRC < 0)
                {
                    throw new Exception("Error reported in Stored Procedure: " + objParams.Parmeters["RC"].Value.ToString());
                }
                objCmd.Connection.Close();
            }
            catch (Exception) { throw; }
            return(objThisYearsDate);
        }
        public IEnumerable<ThisYearsDate> SelThisYearsDates()
        {
            //Set up the variables
            int intRC = 0;
            SqlDataReader dr;
            List<ThisYearsDate> retVal = new List<ThisYearsDate>();

            //Set up the parameters using my custom parameter factory
            IParameterFactory objParams = new ThisYearsDateParameterFactory();

            try
            {
                using (SqlConnection sqlConnection = new ADOConnectionFactory().Connection)
                {
                    sqlConnection.Open();
                    using (SqlCommand sqlCommand = new SqlCommand())
                    {

                        sqlCommand.Connection = sqlConnection;

                        sqlCommand.Parameters.Add((objParams.Parameters["RC"]));

                        //call stored procedure to insert record
                        sqlCommand.CommandType = CommandType.StoredProcedure;
                        sqlCommand.CommandText = "pSelThisYearsDates";

                        dr = sqlCommand.ExecuteReader();

                        while (dr.Read())
                        {
                            ThisYearsDate tyd = new ThisYearsDate();
                            tyd._dateID = (int)dr["dateID"];
                            tyd._dateName = (string)dr["dateName"];
                            retVal.Add(tyd);
                        }

                        dr.Close();

                        //check the return code for errors
                        intRC = (int)objParams.Parameters["RC"].Value;
                        if (intRC < 0)
                        {
                            throw new Exception("Error reported in Stored Procedure: " + objParams.Parameters["RC"].Value.ToString());
                        }

                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            return retVal;
        }