Project_Marmelade.Business.OptimizationBusiness.OptimPersist.GetFruitInfo C# (CSharp) Method

GetFruitInfo() public method

public GetFruitInfo ( ) : List
return List
        public List<Fruit> GetFruitInfo()
        {
            List<Fruit> dbFruit = new List<Fruit>();
            try
            {
                SqlCommand cmd = new SqlCommand("spGetFruitInfo", conn);
                cmd.CommandType = CommandType.StoredProcedure;

                SqlDataReader rdr = cmd.ExecuteReader();

                while (rdr.HasRows && rdr.Read())
                {
                    dbFruit.Add(new Fruit((string)rdr["Name"], (int)rdr["AmountAvailable"], (decimal)rdr["PricePrKg"]));
                }

            }
            catch (SqlException e)
            {
                string s = e.Message;
            }
            finally
            {
                conn.Close();
                conn.Dispose();
            }

            return dbFruit;
        }

Usage Example

        public List<Fruit> GetFruitInfo()
        {
            OptimPersist db = new OptimPersist();
            List<Fruit> fruitList = db.GetFruitInfo();

            return fruitList;
        }