//Een nieuw genre toevoegen in database public static int AddGenre(Genre genre) { try { String sSQL = "INSERT INTO Genre(Name) VALUES(@Name)"; DbParameter par1 = Database.AddParameter("@Name", genre.Name); if (par1.Value == null) par1.Value = DBNull.Value; DbParameter[] pars = new DbParameter[] { par1 }; int affected = Database.ModifyData(sSQL, pars); return affected; } catch (Exception ex) { Console.WriteLine(ex.Message); return 0; } }
//Een bestaand genre bewerken public static int EditGenre(Genre genre) { try { String sSQL = "Update Genre Set Name=@Name WHERE ID=@ID"; DbParameter par1 = Database.AddParameter("@Name", genre.Name); if (par1.Value == null) par1.Value = DBNull.Value; DbParameter par2 = Database.AddParameter("@ID", genre.Id); if (par2.Value == null) par2.Value = DBNull.Value; DbParameter[] pars = new DbParameter[] { par1, par2 }; int affected = Database.ModifyData(sSQL, pars); return affected; } catch (Exception ex) { Console.WriteLine(ex.Message); return 0; } }