//methods public List <ProductenInBestelling> getProductenInBestellingFromDB(string connectionstring, int idBestelling) { //de connectie met de databank maken MySqlConnection conn = new MySqlConnection(connectionstring); //Het SQL-commando definiëren MySqlCommand cmd = new MySqlCommand(" Select * from cafétoepassing_smeyers_tom_gip.bestelling_has_producten" + " where bestelling_idbestelling = @idbestelling ", conn); cmd.Parameters.AddWithValue("idbestelling", idBestelling); List <ProductenInBestelling> productenInBestellingLijst = new List <ProductenInBestelling>(); conn.Open(); MySqlDataReader dataReader = cmd.ExecuteReader(); while (dataReader.Read()) { ProductenInBestelling item = new ProductenInBestelling( Convert.ToInt16(dataReader[0]), Convert.ToInt16(dataReader[1]), Convert.ToDouble(dataReader[2]) ); productenInBestellingLijst.Add(item); } conn.Close(); return(productenInBestellingLijst); }
public void addProductenInBestelling(ProductenInBestelling item) { ProductenInBestellingMapper mapper = new ProductenInBestellingMapper(); try { mapper.addProductenInBestellingToDB(_connectionString, item); } catch (Exception ex) { mapper.updateProductenInBestellingToDB(_connectionString, item); } }
public void addProductenInBestellingToDB(string connectionstring, ProductenInBestelling item) { //de connectie met de databank maken MySqlConnection conn = new MySqlConnection(connectionstring); //Het SQL-commando definiëren string opdracht = "INSERT INTO cafétoepassing_smeyers_tom_gip.bestelling_has_producten(bestelling_idbestelling, Producten_idProducten, Aantal) VALUES(@bestelling_idbestelling, @Producten_idProducten, @aantal)"; MySqlCommand cmd = new MySqlCommand(opdracht, conn); //voeg de waarden toe, je haalt ze uit het object eval cmd.Parameters.AddWithValue("bestelling_idbestelling", item.IdBestelling); cmd.Parameters.AddWithValue("Producten_idProducten", item.IdProducten); cmd.Parameters.AddWithValue("aantal", item.Aantal); conn.Open(); cmd.ExecuteNonQuery(); conn.Close(); }
public void updateProductenInBestellingToDB(string connectionstring, ProductenInBestelling item) { //de connectie met de databank maken MySqlConnection conn = new MySqlConnection(connectionstring); //Het SQL-commando definiëren string opdracht = "UPDATE cafétoepassing_smeyers_tom_gip.bestelling_has_producten" + " SET Aantal = aantal + @aantal" + " WHERE bestelling_idbestelling = @bestelling_idbestelling" + " AND Producten_idProducten= @Producten_idProducten"; MySqlCommand cmd = new MySqlCommand(opdracht, conn); //voeg de waarden toe, je haalt ze uit het object eval cmd.Parameters.AddWithValue("aantal", item.Aantal); cmd.Parameters.AddWithValue("bestelling_idbestelling", item.IdBestelling); cmd.Parameters.AddWithValue("Producten_idProducten", item.IdProducten); conn.Open(); cmd.ExecuteNonQuery(); conn.Close(); }