Esempio n. 1
0
        private void btnConfirm_Click(object sender, EventArgs e)
        {
            try
            {
                string          conString = "Server=127.0.0.1;Database=myDB;Uid=root;Pwd=softkitty1";
                MySqlConnection con       = new MySqlConnection(conString);

                string       query1 = "SET FOREIGN_KEY_CHECKS=0";
                MySqlCommand cmd1   = new MySqlCommand(query1, con);
                con.Open();
                cmd1.ExecuteNonQuery();
                con.Close();

                string query = "insert into myDB.animals(class, species,nickname,gender,age,foodtype,zookeeper) values('"
                               + this.textClass.Text + "','" + this.textSpecies.Text + "','" + this.textNickname.Text + "','"
                               + this.textGender.Text + "','" + this.textAge.Text + "','" + this.textFood.Text + "','" + this.textZookeeper.Text + "');";
                MySqlCommand cmd = new MySqlCommand(query, con);
                con.Open();
                cmd.ExecuteNonQuery();
                con.Close();

                string       query2 = "SET FOREIGN_KEY_CHECKS=1";
                MySqlCommand cmd2   = new MySqlCommand(query2, con);
                con.Open();
                cmd2.ExecuteNonQuery();
                con.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            animalsForm.updateAnimalsData();
            this.Close();
        }
Esempio n. 2
0
        private void btnSaveUpdated_Click(object sender, EventArgs e)
        {
            int position = -1;

            if (combo != null)
            {
                position = combo.SelectedIndex + 1;
            }
            try
            {
                string          conString = "Server=127.0.0.1;Database=myDB;Uid=root;Pwd=softkitty1";
                MySqlConnection con       = new MySqlConnection(conString);

                string       query1 = "SET FOREIGN_KEY_CHECKS=0";
                MySqlCommand cmd1   = new MySqlCommand(query1, con);
                con.Open();
                cmd1.ExecuteNonQuery();
                con.Close();

                string       query = @"update myDB.animals set nickname=@Nickname, foodType=@Food
                                where animalId=@id";
                MySqlCommand cmd   = new MySqlCommand(query, con);

                con.Open();
                cmd.Parameters.AddWithValue("@Nickname", this.updateAnimalsDataGridView.CurrentRow.Cells[4].Value.ToString());

                cmd.Parameters.AddWithValue("@Food", position.ToString());
                cmd.Parameters.AddWithValue("@id", this.updateAnimalsDataGridView.CurrentRow.Cells[0].Value.ToString());
                cmd.ExecuteNonQuery();
                con.Close();

                string       query2 = "SET FOREIGN_KEY_CHECKS=1";
                MySqlCommand cmd2   = new MySqlCommand(query2, con);
                con.Open();
                cmd2.ExecuteNonQuery();
                con.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            animalsForm.updateAnimalsData();
            this.Close();
        }
Esempio n. 3
0
 private void btnSaveFoodChanges_Click(object sender, EventArgs e)
 {
     animalsForm.updateAnimalsData();
 }