private void button2_Click(object sender, EventArgs e) { try { string Query = "update um_db.notizen set m_vorname='" + this.txtVorname.Text + "', m_nachname='" + this.txtNachname.Text + "', kommentar='" + this.txtKommentar.Text + "', datum='" + this.dateTimePicker1.Text + "' where NID='" + this.txtNID.Text + "' ;"; MySqlConnection conDataBase = new MySqlConnection(constring); MySqlCommand cmdDataBase = new MySqlCommand(Query, conDataBase); MySqlDataReader myReader; //Connection Open conDataBase.Open(); myReader = cmdDataBase.ExecuteReader(); MessageBox.Show("Die Daten wurden aktualisiert.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); while (myReader.Read()) { } //Refresh datagridview on form Notizen obj.load_table(); obj.dataGridView1.Update(); obj.dataGridView1.Refresh(); //Close Connection conDataBase.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { this.Close(); } }
private void btnSave_Click(object sender, EventArgs e) { //Get date and time Now DateTime dateTimeNow = DateTime.Now; DateTime dateNow = Convert.ToDateTime(dateTimeNow); try { string Query = "insert into um_db.notizen (kommentar,username,m_vorname,m_nachname,datum) values('" + this.txtKommentar.Text + "','" + this.txtBenutzer2.Text + "','" + this.txtVorname.Text + "','" + this.txtNachname2.Text + "','" + this.dateTimePicker1.Text + "') ;"; MySqlConnection conDataBase = new MySqlConnection(constring); MySqlCommand cmdDataBase = new MySqlCommand(Query, conDataBase); MySqlDataReader myReader; //Connection Open conDataBase.Open(); myReader = cmdDataBase.ExecuteReader(); MessageBox.Show("Kommentar erfolgreich eingegeben.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); while (myReader.Read()) { } //Refresh datagridview on form Notizen obj.load_table(); obj.dataGridView1.Update(); obj.dataGridView1.Refresh(); //Close Connection conDataBase.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { //Insert into nachrichten START ************************************************************** try //Insert into Nachrichten start { string Query_notizenMsg = "insert into um_db.nachrichten (msg,menu,datetime) values('" + this.txtKommentar.Text + "','" + "Notizen" + "','" + dateNow + "');"; MySqlConnection conDataBase_notizenMsg = new MySqlConnection(constring); MySqlCommand cmdDataBase_notizenMsg = new MySqlCommand(Query_notizenMsg, conDataBase_notizenMsg); MySqlDataReader myReader_notizenMsg; //Open Connection conDataBase_notizenMsg.Open(); myReader_notizenMsg = cmdDataBase_notizenMsg.ExecuteReader(); while (myReader_notizenMsg.Read()) { } //Close Connection conDataBase_notizenMsg.Close(); } catch (Exception ex) { MessageBox.Show("Notizen Fehler: in Nachrichten eingeben!"); MessageBox.Show(ex.Message); } //Insert into Nachrichten end //Insert into nachrichten END ****************************************************************** this.Close(); } }