public static List<Postcode> GetList() { List<Postcode> pclijst = new List<Postcode>(); SqlConnection connection = DB.GetConnection(); SqlCommand selectCommand = new SqlCommand("SELECT * FROM Postcode", connection); pclijst.Clear(); try { connection.Open(); SqlDataReader reader = selectCommand.ExecuteReader(); while (reader.Read()) { Postcode pc = new Postcode(); pc.PostcodeID = (int)reader["PostcodeID"]; pc.Code = reader["Postcode"].ToString(); pc.Gemeente = reader["Gemeente"].ToString(); pc.Provincie = reader["Provincie"].ToString(); pclijst.Add(pc); } reader.Close(); } catch (SqlException ex) { throw ex; } finally { connection.Close(); } return pclijst; }
public static Postcode Get(int postcodeid) { Postcode postcode = new Postcode(); SqlConnection connection = DB.GetConnection(); SqlCommand selectCommand = new SqlCommand("SELECT * FROM Postcode WHERE PostcodeID= @postcodeid", connection); selectCommand.Parameters.AddWithValue("@postcodeid", postcodeid); try { connection.Open(); SqlDataReader reader = selectCommand.ExecuteReader(); if (reader.Read()) { postcode.PostcodeID = (int)reader["PostcodeID"]; postcode.Code = reader["Postcode"].ToString(); postcode.Gemeente = reader["Gemeente"].ToString(); postcode.Provincie = reader["Provincie"].ToString(); } reader.Close(); } catch (SqlException ex) { throw ex; } finally { connection.Close(); } return postcode; }
// methods public static void Initialize() { SqlConnection connection = DB.GetConnection(); SqlCommand selectCommand = new SqlCommand("SELECT * FROM Postcode", connection); all_postcodes.Clear(); try { connection.Open(); SqlDataReader reader = selectCommand.ExecuteReader(); while (reader.Read()) { Postcode pc = new Postcode(); pc.PostcodeID = (int)reader["PostcodeID"]; pc.Code = reader["Postcode"].ToString(); pc.Gemeente = reader["Gemeente"].ToString(); pc.Provincie = reader["Provincie"].ToString(); all_postcodes.Add(pc); } reader.Close(); } catch (SqlException ex) { throw ex; } finally { connection.Close(); } }
// overrides public override string ToString() { string s = ""; Postcode pc = new Postcode(); pc = PostcodeDB.Get(PostcodeID); s += "Naam, Voornaam: " + Achternaam + ", " + Voornaam + Environment.NewLine; s += "Adres : " + Straat + " " + Huisnummer + ", " + pc.Code + " " + pc.Gemeente + Environment.NewLine; s += "Geboortedatum : " + Geboortedatum.ToShortDateString() + Environment.NewLine; s += "Telefoonnummer: " + Tools.FormatTelefoonnummer(Telefoonnummer) + Environment.NewLine; ; return s; }