コード例 #1
0
        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();
            }
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: sskhaustov/dbb_RealEstate
 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();
 }