public List <Tour_Model> PopulateTours() { List <Tour_Model> tours = new List <Tour_Model>(); Connection(); SqlDataReader reader; SqlCommand cmd = new SqlCommand("SELECT * FROM Tour", con); try { con.Open(); reader = cmd.ExecuteReader(); while (reader.Read()) { Tour_Model tour = new Tour_Model(); tour.TourArea = (reader["TourArea"].ToString()); tour.CompanyID = int.Parse(reader["CompanyID"].ToString()); tour.TimeDurationMins = int.Parse(reader["TimeDurationMins"].ToString()); tours.Add(tour); } } catch (Exception ex) { message = ex.Message; } finally { con.Close(); } return(tours); }
public List <Tour_Model> ShowAllTours()//New { Connection(); SqlDataReader reader; List <Tour_Model> toursList = new List <Tour_Model>(); SqlCommand cmd = new SqlCommand("uspShowAllTours", con); cmd.CommandType = CommandType.StoredProcedure; try { con.Open(); reader = cmd.ExecuteReader(); while (reader.Read()) { Tour_Model tours = new Tour_Model(); //tours.TourID = int.Parse(reader["TourID"].ToString()); tours.CompanyID = int.Parse(reader["CompanyID"].ToString()); tours.TourArea = reader["TourArea"].ToString(); tours.TimeDurationMins = int.Parse(reader["TimeDurationMins"].ToString()); tours.PricePerPerson = decimal.Parse(reader["Price"].ToString()); toursList.Add(tours); } } catch (Exception ex) { message = "Error " + ex.Message; } finally { con.Close(); } return(toursList); }