0

Been trying to figure out this for 30 min and still don't get why this won't update the values... after i clicked the update button nothing happens... here is the code

        try
        {
            MySqlConnection connection = new MySqlConnection(MyConnectionString);
            MySqlCommand cmd;
            connection.Open();
            cmd = connection.CreateCommand();
            cmd.CommandText = "UPDATE student_info SET SEM = @SEM, STUDENT_NO = @STUDENT_NO, LASTNAME = @LASTNAME" +
            ", FIRSTNAME = @FIRSTNAME, MIDDLENAME = @MIDDLENAME, CITY = @CITY, STREET = @STREET, GENDER = @GENDER" +
            ", COURSE = @COURSE, YEAR = @YEAR, SECTION = @SECTION, BIRTHDAY = @BIRTHDAY  Where STUDENT_NO = @STUDENT_NO";

            cmd.Parameters.AddWithValue("@SEM", sem_combo.Text);
            cmd.Parameters.AddWithValue("@STUDENT_NO", studentNo_txt.Text);
            cmd.Parameters.AddWithValue("@LASTNAME", lname_txt.Text);
            cmd.Parameters.AddWithValue("@FIRSTNAME", fname_txt.Text);
            cmd.Parameters.AddWithValue("@MIDDLENAME", mname_txt.Text);
            cmd.Parameters.AddWithValue("@CITY", address_txt.Text);
            cmd.Parameters.AddWithValue("@STREET", street_txt.Text);
            cmd.Parameters.AddWithValue("@GENDER", gender_combo.Text);
            cmd.Parameters.AddWithValue("@COURSE", program_combo.Text);
            cmd.Parameters.AddWithValue("@YEAR", yr_combo.Text);
            cmd.Parameters.AddWithValue("@SECTION", section_combo.Text);
            cmd.Parameters.AddWithValue("@BIRTHDAY", bday.Text);
            cmd.ExecuteNonQuery();
            cmd.Parameters.Clear();

            cmd.CommandText = "UPDATE contacts SET EMAIL = @EMAIL, CELL_NO = @CELL_NO Where STUDENT_NO = @STUDENT_NO";

            cmd.Parameters.AddWithValue("@EMAIL", email_txt.Text);
            cmd.Parameters.AddWithValue("@CELL_NO", contact_txt.Text);
            cmd.Parameters.AddWithValue("@STUDENT_NO", studentNo_txt.Text);
            cmd.ExecuteNonQuery();
            cmd.Parameters.Clear();
            MessageBox.Show("updated");
        }
        catch(Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
davz_11
  • 135
  • 2
  • 6
  • 14
  • You dont recieve a error message neither? – Mad Dog Tannen Mar 12 '14 at 13:13
  • In your second query you have **three** parameters in your command text.But you are giving value only **two** of them. – Selman Genç Mar 12 '14 at 13:14
  • http://stackoverflow.com/questions/22351793/fatal-error-encountered-during-command-execution-during-update – Soner Gönül Mar 12 '14 at 13:15
  • Are you executing inside an uncommited transaction? Does the value you pass to the `Student_No` parameter exist in the database? Try to profile your session to see what statements are actually sent to the database. Most likely, the values are not what you think they are and you are trying to update a non-existent record – Panagiotis Kanavos Mar 12 '14 at 13:16
  • @Selman22 already done that... still won't work – davz_11 Mar 12 '14 at 13:16
  • 1
    You just asked this question in http://stackoverflow.com/questions/22351793/fatal-error-encountered-during-command-execution-during-update Your code is identical, yet now you say nothing happens? – Golden Dragon Mar 12 '14 at 13:16
  • @GoldenDragon sorry i just noticed it right now – davz_11 Mar 12 '14 at 13:36

0 Answers0