Ejemplo n.º 1
0
        private void button9_Click(object sender, EventArgs e)
        {
            string     stname = "", dur = "";
            AddStation w = new AddStation();

            w.ShowDialog();
            if (w.DialogResult == DialogResult.OK)
            {
                w.get_data(out stname, out dur);
                try
                {
                    mconnect.Open();

                    //генерация ключа
                    int k = KEY_GEN(@"SELECT skey FROM Metro");

                    cmd[0]             = new MySqlCommand();
                    cmd[0].Connection  = mconnect;
                    cmd[0].CommandText = @"INSERT INTO Metro(facility_m, Station, Duration, skey)
                                      VALUES(
                                            @id,
                                            @stn,
                                            @d,
                                            @ke)";
                    cmd[0].Prepare();
                    cmd[0].Parameters.AddWithValue("@id", _id);
                    cmd[0].Parameters.AddWithValue("@stn", stname);
                    cmd[0].Parameters.AddWithValue("@d", dur);
                    cmd[0].Parameters.AddWithValue("@ke", k);
                    cmd[0].ExecuteNonQuery();

                    stm               = "SELECT Station, Duration FROM Metro WHERE Metro.facility_m = @id";
                    cmd[0]            = new MySqlCommand(stm);
                    cmd[0].Connection = mconnect;
                    cmd[0].Prepare();
                    cmd[0].Parameters.AddWithValue("@id", _id);
                    da[7] = new MySqlDataAdapter(cmd[0]);
                    ds[7].Clear();
                    da[7].Fill(ds[7], "Metro");
                    dataGridView8.DataSource = ds[7].Tables["Metro"];
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
                if (mconnect != null)
                {
                    mconnect.Close();
                }
            }
        }
Ejemplo n.º 2
0
        private void button9_Click(object sender, EventArgs e)
        {
            string stname = "", dur = "";
            AddStation w = new AddStation();
            w.ShowDialog();
            if (w.DialogResult == DialogResult.OK)
            {
                w.get_data(out stname, out dur);
                try
                {
                    mconnect.Open();

                    //генерация ключа
                    int k = KEY_GEN(@"SELECT skey FROM Metro");

                    cmd[0] = new MySqlCommand();
                    cmd[0].Connection = mconnect;
                    cmd[0].CommandText = @"INSERT INTO Metro(facility_m, Station, Duration, skey)
                                      VALUES(
                                            @id,
                                            @stn,
                                            @d,
                                            @ke)";
                    cmd[0].Prepare();
                    cmd[0].Parameters.AddWithValue("@id", _id);
                    cmd[0].Parameters.AddWithValue("@stn", stname);
                    cmd[0].Parameters.AddWithValue("@d", dur);
                    cmd[0].Parameters.AddWithValue("@ke", k);
                    cmd[0].ExecuteNonQuery();

                    stm = "SELECT Station, Duration FROM Metro WHERE Metro.facility_m = @id";
                    cmd[0] = new MySqlCommand(stm);
                    cmd[0].Connection = mconnect;
                    cmd[0].Prepare();
                    cmd[0].Parameters.AddWithValue("@id", _id);
                    da[7] = new MySqlDataAdapter(cmd[0]);
                    ds[7].Clear();
                    da[7].Fill(ds[7], "Metro");
                    dataGridView8.DataSource = ds[7].Tables["Metro"];
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
                if (mconnect != null)
                    mconnect.Close();
            }
        }