//public Verhaal(string titel, string beschrijving, string coverart) //{ // this.titel = titel; // this.beschrijving = beschrijving; // this.coverart = coverart; //} public Verhaal(int id, string titel, string beschrijving, VerhaalGenres genre, int auteurID) { this.id = id; this.titel = titel; this.beschrijving = beschrijving; this.auteurid = auteurID; this.VerhaalGenre = genre; }
public List <Verhaal> GetListVerhalen(int id) { List <Verhaal> F = new List <Verhaal>(); Verhaal V = new Verhaal(); using (SqlConnection conn = new SqlConnection(ConnectionString)) { conn.Open(); string query = "SELECT * from Verhaal WHERE AuteurID = @ID"; using (SqlCommand cmd = new SqlCommand(query, conn)) { cmd.CommandType = CommandType.Text; cmd.Parameters.AddWithValue("@ID", id); cmd.ExecuteNonQuery(); SqlDataAdapter adapt = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); adapt.Fill(ds); int count = ds.Tables[0].Rows.Count; //conn.Close(); if (count > 0) { using (SqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { // get everything from the things and make a new obj int ID = (int)reader["ID"]; string Titel = (string)reader["Titel"]; string Desc = (string)reader["Beschrijving"]; string genre = ((string)reader["Genre"]); int AutID = (int)reader["AuteurID"]; // Enum.TryParse(genre, out VerhaalGenres genres); VerhaalGenres MyGenres = (VerhaalGenres)Enum.Parse(typeof(VerhaalGenres), genre, true); V = new Verhaal(ID, Titel, Desc, MyGenres, AutID); F.Add(V); } } } } return(F); } }