private List<CitiesViewModel> GetCityList(string query) { SqlConnection connection = new SqlConnection(connectionString); connection.Open(); SqlCommand command = new SqlCommand(query, connection); SqlDataReader reader = command.ExecuteReader(); List<CitiesViewModel> cities = new List<CitiesViewModel>(); int sl = 1; while (reader.Read()) { CitiesViewModel city = new CitiesViewModel(); city.Sl = sl++; city.CityName = reader["CityName"].ToString(); city.CityAbout = reader["CityAbout"].ToString(); city.NoOfDwellers = Convert.ToInt32(reader["NoOfDwellers"].ToString()); city.Location = reader["Location"].ToString(); city.Weather = reader["Weather"].ToString(); city.CountryName = reader["CountryName"].ToString(); city.CountryAbout = reader["CountryAbout"].ToString(); cities.Add(city); } return cities; }
private List <CitiesViewModel> GetCityList(string query) { SqlConnection connection = new SqlConnection(connectionString); connection.Open(); SqlCommand command = new SqlCommand(query, connection); SqlDataReader reader = command.ExecuteReader(); List <CitiesViewModel> cities = new List <CitiesViewModel>(); int sl = 1; while (reader.Read()) { CitiesViewModel city = new CitiesViewModel(); city.Sl = sl++; city.CityName = reader["CityName"].ToString(); city.CityAbout = reader["CityAbout"].ToString(); city.NoOfDwellers = Convert.ToInt32(reader["NoOfDwellers"].ToString()); city.Location = reader["Location"].ToString(); city.Weather = reader["Weather"].ToString(); city.CountryName = reader["CountryName"].ToString(); city.CountryAbout = reader["CountryAbout"].ToString(); cities.Add(city); } return(cities); }