public PostalCode getCityByZip(int zipcode=0) { PostalCode pc = new PostalCode (); List<PostalCode> postalcodes = execute ("WHERE Zipcode = " + zipcode); if (postalcodes.Count > 0) { pc = postalcodes [0]; } return pc; }
private List<PostalCode> execute(string sqlwhere) { List<PostalCode> postalcodes = new List<PostalCode>(); var connection = DbHelper.GetConnection(); if (!connection.Equals (null)) { using (var cmd = connection.CreateCommand()) { connection.Open(); cmd.CommandText = "SELECT * FROM vw_zipcodes " + sqlwhere; using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { PostalCode pc = new PostalCode(); pc.zipcode = reader.GetInt32(reader.GetOrdinal("Zipcode")); pc.city = StringHelper.ToTitleCase(reader.GetString(reader.GetOrdinal("City"))); pc.state = reader.GetString(reader.GetOrdinal("State")); pc.state_abbr = reader.GetString(reader.GetOrdinal("Abbr")); postalcodes.Add(pc); } } connection.Close(); } } return postalcodes; }