public List <Gebruiker> GetAllGebruikers() { List <Gebruiker> list = new List <Gebruiker>(); try { using (SqlConnection conn = new SqlConnection(sqlcon.connectionstring())) { using (SqlCommand cmd = new SqlCommand()) { string query = @"USE [Mauro_SQL]; Select* FROM Table_Gebruiker;"; cmd.CommandText = query; cmd.Connection = conn; conn.Open(); using (SqlDataReader sdr = cmd.ExecuteReader()) { if (sdr.HasRows) { while (sdr.Read()) { list.Add(new Gebruiker( sdr["Gebruikersnaam"].ToString(), sdr["Voornaam"].ToString(), sdr["Achternaam"].ToString(), sdr["MailAdress"].ToString(), Convert.ToInt32(sdr["GebruikerID"]))); } } } } } } catch (Exception ex) { // write to log Console.WriteLine(ex.Message); } return(list); }
public List <Bewonersaldo> AlleactieveBewonersaldos(int studentenhuisId) { List <Bewonersaldo> ret = new List <Bewonersaldo>(); try { using (SqlConnection conn = new SqlConnection(sqlcon.connectionstring())) { using (SqlCommand cmd = new SqlCommand()) { string query = $"Select GebruikerID, Voornaam, Saldo from vwActiveStudentenhuisGebruikers WHERE studenthuisid = @studentenhuisid"; cmd.CommandText = query; cmd.Connection = conn; cmd.Parameters.AddWithValue("@studentenhuisid", studentenhuisId); conn.Open(); using (SqlDataReader sdr = cmd.ExecuteReader()) { if (sdr.HasRows) { while (sdr.Read()) { ret.Add(new Bewonersaldo() { GebruikerID = (int)sdr["GebruikerID"], Saldo = (int)sdr["Saldo"], Voornaam = (string)sdr["Voornaam"] }); } } } } } } catch (Exception) { //OOPS } return(ret); }