// public class constructor
        public clsFoodCollection()
        {
            clsDataConnection DB = new clsDataConnection();

            DB.Execute("sproc_tblFood_SelectAll");
            // get the count
            Int32 RecordCount = DB.Count;
            // set index
            Int32 Index = 0;

            // while loop
            while (Index < RecordCount)
            {
                // create class instance
                clsFood Food = new clsFood();
                // get data
                Food.FoodID    = Convert.ToInt32(DB.DataTable.Rows[Index]["FoodID"]);
                Food.FoodName  = Convert.ToString(DB.DataTable.Rows[Index]["FoodName"]);
                Food.FoodType  = Convert.ToString(DB.DataTable.Rows[Index]["FoodType"]);
                Food.SellPrice = Convert.ToDecimal(DB.DataTable.Rows[Index]["SellPrice"]);
                // add record
                mFoods.Add(Food);
                // increment index
                Index++;
            }
        }
Example #2
0
        //public constructor for the class
        public clsFoodCollection()
        {
            //var for the index
            Int32 Index = 0;
            //var to store the record count
            Int32 RecordCount = 0;
            //object for data connection
            clsDataConnection DB = new clsDataConnection();

            //execute the stored procedure
            DB.Execute("sproc_tblFood_SelectAll");
            //get the count of records
            RecordCount = DB.Count;
            //while there are records to process
            while (Index < RecordCount)
            {
                //create a blank address
                clsFood AFood = new clsFood();
                //read in the fields from the current record
                AFood.FoodID    = Convert.ToInt32(DB.DataTable.Rows[Index]["FoodID"]);
                AFood.FoodName  = Convert.ToString(DB.DataTable.Rows[Index]["FoodName"]);
                AFood.FoodPrice = Convert.ToString(DB.DataTable.Rows[Index]["FoodPrice"]);
                AFood.Quantity  = Convert.ToString(DB.DataTable.Rows[Index]["Quantity"]);
                //add the record to the private data member
                foodList.Add(AFood);
                //point at the next record
                Index++;
            }
        }