public bool faID(Nafn nafn) { SqlCommand command = new SqlCommand("finnaid", this.connection); command.CommandType = CommandType.StoredProcedure; command.Parameters.Add("@id", SqlDbType.VarChar).Value = nafn.ID; this.connection.Open(); SqlDataReader dr = command.ExecuteReader(); dr.Read(); try { nafn.Kennitala = dr.GetString(1); nafn.Fulltnafn = dr.GetString(2); nafn.Heimilisfang = dr.GetString(3); nafn.Postnumer = dr.GetInt32(4); } catch { this.connection.Close(); return(false); } this.connection.Close(); return(true); }
public List <Nafn> faNafn(Nafn nafn) { List <Nafn> nofn = new List <Nafn>(); SqlCommand command = new SqlCommand("finnanafn", this.connection); command.CommandType = CommandType.StoredProcedure; command.Parameters.Add("@nafn", SqlDbType.VarChar).Value = nafn.Fulltnafn; this.connection.Open(); SqlDataReader dr = command.ExecuteReader(); while (dr.Read()) { nofn.Add(new Nafn(dr.GetInt32(0), dr.GetString(1), dr.GetString(2), dr.GetString(3), dr.GetInt32(4))); } this.connection.Close(); return(nofn); }
private void btnOK_Click(object sender, EventArgs e) { textBox1.Text = ""; if (rBID.Checked) { Nafn nafn = new Nafn(); try { nafn.ID = int.Parse(txtLeita.Text); } catch { textBox1.Text = "Villa kom upp"; } if (sql.faID(nafn)) { textBox1.Text = nafn.ToString(); } else { textBox1.Text = "Þetta ID fannst ekki"; } } if (rBKT.Checked) { Nafn nafn = new Nafn(); nafn.Kennitala = txtLeita.Text; List <Nafn> nofn = sql.faKT(nafn); if (nofn.Count == 0) { textBox1.Text = "Ekkert fannst"; } for (int i = 0; i < nofn.Count; i++) { textBox1.AppendText(nofn[i].ToString()); } } if (rBHeimilisfang.Checked) { Nafn nafn = new Nafn(); nafn.Heimilisfang = txtLeita.Text; List <Nafn> nofn = sql.faHeimilisfang(nafn); if (nofn.Count == 0) { textBox1.Text = "Ekkert fannst"; } for (int i = 0; i < nofn.Count; i++) { textBox1.AppendText(nofn[i].ToString()); } } if (rBPostnr.Checked) { Nafn nafn = new Nafn(); try { nafn.Postnumer = int.Parse(txtLeita.Text); } catch { textBox1.Text = "Villa kom upp"; } List <Nafn> nofn = sql.faPostnr(nafn); if (nofn.Count == 0) { textBox1.Text = "Ekkert fannst"; } for (int i = 0; i < nofn.Count; i++) { textBox1.AppendText(nofn[i].ToString()); } } if (rBNafn.Checked) { Nafn nafn = new Nafn(); nafn.Fulltnafn = txtLeita.Text; List <Nafn> nofn = sql.faNafn(nafn); if (nofn.Count == 0) { textBox1.Text = "Ekkert fannst"; } for (int i = 0; i < nofn.Count; i++) { textBox1.AppendText(nofn[i].ToString()); } } }