示例#1
0
        /// <summary>
        /// Method to get all categories
        /// </summary>	    	 
        public IList<CategoryInfo> GetCategories()
        {
            IList<CategoryInfo> categories = new List<CategoryInfo>();

            //Execute a query to read the categories
            using(SqlDataReader rdr = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_CATEGORIES, null)) {
                while (rdr.Read()) {
                    CategoryInfo cat = new CategoryInfo(rdr.GetString(0), rdr.GetString(1), rdr.GetString(2));
                    categories.Add(cat);
                }
            }
            return categories;
        }
示例#2
0
        /// <summary>
        /// Get an individual category based on a provided id
        /// </summary>
        /// <param name="categoryId">Category id</param>
        /// <returns>Details about the Category</returns>
        public CategoryInfo GetCategory(string categoryId)
        {
            //Set up a return value
            CategoryInfo category = null;

            //Create a parameter
            SqlParameter parm = new SqlParameter(PARM_CATEGORY_ID, SqlDbType.VarChar, 10);
            //Bind the parameter
            parm.Value = categoryId;

            //Execute the query
            using (SqlDataReader rdr = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_CATEGORY, parm)) {
                if (rdr.Read())

                    category = new CategoryInfo(rdr.GetString(0), rdr.GetString(1), rdr.GetString(2));
                else
                    category = new CategoryInfo();
            }
            return category;
        }