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;
}