public int InsertBestellung(Bestellung b) { int bestellnr = -1; try { MySqlCommand comm = con.CreateCommand(); comm.CommandText = "INSERT INTO bestellung VALUES (NULL,'" + b.BestDatum1 + "'," + b.BestKunde1 + ");"; comm.ExecuteNonQuery(); comm.CommandText = "SELECT MAX(BestNr) FROM bestellung;"; MySqlDataReader reader = comm.ExecuteReader(); if (reader.Read()) { bestellnr = reader.GetInt32(0); } reader.Close(); } catch (Exception ex) { MessageBox.Show("Neue Bestellung: " + ex.Message); } return(bestellnr); }
private void btnNewBestellung_Click(object sender, EventArgs e) { tbBestellDatum.Text = DateTime.Now.ToString(); int knr = liKunden[cbBestellKunden.SelectedIndex].KdnNr1; if (knr < 1) { MessageBox.Show("Bitte Kunden auswählen!"); } else { Bestellung b = new Bestellung(-1, tbBestellDatum.Text, knr); bestellnr = db.InsertBestellung(b); tbBestellNr.Text = bestellnr.ToString(); } }