private void button3_Click(object sender, EventArgs e) { string number = "", email = ""; try { mconnect.Open(); AddContacts v = new AddContacts(); v.ShowDialog(); if (v.DialogResult == DialogResult.OK) { v.get_data(out number, out email); cmd[0] = new MySqlCommand(); cmd[1] = new MySqlCommand(); cmd[0].Connection = mconnect; cmd[1].Connection = mconnect; if (number != "") { cmd[0].CommandText = @"INSERT INTO PhoneNumbers(citizen_pn, PhoneNumber) VALUES( @INN, @number)"; cmd[0].Prepare(); cmd[0].Parameters.AddWithValue("@INN", _inn); cmd[0].Parameters.AddWithValue("@number", number); cmd[0].ExecuteNonQuery(); } if (email != "") { cmd[1].CommandText = @"INSERT INTO Emails(citizen_e, Email) VALUES( @INN, @email)"; cmd[1].Prepare(); cmd[1].Parameters.AddWithValue("@INN", _inn); cmd[1].Parameters.AddWithValue("@email", email); cmd[1].ExecuteNonQuery(); } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } if (mconnect != null) { mconnect.Close(); } }
private void button3_Click(object sender, EventArgs e) { string number = "", email = ""; try { mconnect.Open(); AddContacts v = new AddContacts(); v.ShowDialog(); if (v.DialogResult == DialogResult.OK) { v.get_data(out number, out email); cmd[0] = new MySqlCommand(); cmd[1] = new MySqlCommand(); cmd[0].Connection = mconnect; cmd[1].Connection = mconnect; if (number != "") { cmd[0].CommandText = @"INSERT INTO PhoneNumbers(citizen_pn, PhoneNumber) VALUES( @INN, @number)"; cmd[0].Prepare(); cmd[0].Parameters.AddWithValue("@INN", _inn); cmd[0].Parameters.AddWithValue("@number", number); cmd[0].ExecuteNonQuery(); } if (email != "") { cmd[1].CommandText = @"INSERT INTO Emails(citizen_e, Email) VALUES( @INN, @email)"; cmd[1].Prepare(); cmd[1].Parameters.AddWithValue("@INN", _inn); cmd[1].Parameters.AddWithValue("@email", email); cmd[1].ExecuteNonQuery(); } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } if (mconnect != null) mconnect.Close(); }