コード例 #1
0
        private void button4_Click(object sender, EventArgs e)
        {
            this.Hide();
            ActTwo a2 = new ActTwo(MyVal);

            a2.ShowDialog();
        }
コード例 #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            MySqlConnection sqlcon = new MySqlConnection(@"server=localhost;user id=root;database=seproject;password=rootpassword");
            MySqlCommand    cmd    = null;
            MySqlDataReader reader = null;

            try
            {
                string sql = "SELECT inGameCurrency FROM seproject.user WHERE username = '******';";

                //sqlcon = new MySqlConnection(Properties.Settings.Default.ConnectionString);
                cmd = new MySqlCommand(sql, sqlcon);

                sqlcon.Open();

                reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    val = reader.GetInt32("inGameCurrency");
                    //lblContinent.Text = reader.GetInt32("continent");
                    //lblRegion.Text = reader.GetString("region");
                    //lblSurfaceArea.Text = string.Format("{0:0.00}", reader.GetFloat("surfacearea"));
                }
                Console.WriteLine(val);
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("An error occurred {0}", ex.Message), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
                if (sqlcon != null)
                {
                    sqlcon.Close();
                }
            }
            MessageBox.Show("Your score is " + score.ToString());
            sum = val + score;
            Console.WriteLine(MyVal);
            //MySqlConnection sqlcon = new MySqlConnection(@"server=localhost;user id=root;database=seproject;password=rootpassword");
            try
            {
                sqlcon.Open();

                string          Query     = "update seproject.user set inGameCurrency = " + "'" + sum + "' where (username = '******');";
                MySqlCommand    cmdInsert = new MySqlCommand(Query, sqlcon);
                MySqlDataReader reader1   = cmdInsert.ExecuteReader();
                MessageBox.Show("Saved");
                while (reader1.Read())
                {
                }
                sqlcon.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Insertion failed");
            }
            ActTwo act2 = new ActTwo(MyVal);

            this.Hide();
            act2.ShowDialog();
        }