public static List <Location.Country> getCountries() { using (SqlConnection sqlConnection = new SqlConnection(connectionString)) { using (SqlCommand command = new SqlCommand("GetCountries", sqlConnection)) { try { sqlConnection.Open(); command.CommandType = CommandType.StoredProcedure; SqlDataReader rdr = command.ExecuteReader(); List <Location.Country> countryList = new List <Location.Country>(); while (rdr.Read()) { Location.Country country = new Location.Country(); country.id = Convert.ToInt32(rdr["id"]); country.Name = rdr["countryname"].ToString(); countryList.Add(country); } return(countryList); } catch (Exception ex) { Console.WriteLine(ex.Message); } return(null); } } }
public static List <Location.Country> getCities(int stateId) { using (SqlConnection sqlConnection = new SqlConnection(connectionString)) { using (SqlCommand command = new SqlCommand("GetCitiesByStateId", sqlConnection)) { try { sqlConnection.Open(); command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@StateId", stateId); SqlDataReader rdr = command.ExecuteReader(); List <Location.Country> countryList = new List <Location.Country>(); while (rdr.Read()) { Location.Country country = new Location.Country(); country.id = Convert.ToInt32(rdr["id"]); country.Name = rdr["name"].ToString(); countryList.Add(country); } return(countryList); } catch (Exception ex) { } return(null); } } }
public static Location.Country getCountry(int countryId) { using (SqlConnection sqlConnection = new SqlConnection(connectionString)) { using (SqlCommand command = new SqlCommand("GetCountryById", sqlConnection)) { try { sqlConnection.Open(); command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@CountryId", countryId); SqlDataReader rdr = command.ExecuteReader(); Location.Country country = new Location.Country(); while (rdr.Read()) { country.id = Convert.ToInt32(rdr["id"]); country.Name = rdr["countryname"].ToString(); } return(country); } catch (Exception ex) { } return(null); } } }