0

I'm having an issue with an update query in C#. It's odd to me that I'm having an issue with update, but select, delete, and insert work.

  public void updateTeacherInfo(string SSN, string Classroom, string salary, string tenured, string phone)
    {

        OracleConnection conn = new OracleConnection("myconnectionstring;");

        conn.Open();
        OracleCommand cmd = new OracleCommand("Update Teachers Set classroom_number = :TRM, Salary = :TSALARY, Tenured = :TTENURE, Phone_numer = :TPHONE Where SSN = :TSSN", conn);
        OracleCommand commit = new OracleCommand("COMMIT", conn);
        cmd.Parameters.Add(new OracleParameter(":TSSN", SSN));
        cmd.Parameters.Add(new OracleParameter(":TRM", Classroom));
        cmd.Parameters.Add(new OracleParameter(":TSALARY", salary));
        cmd.Parameters.Add(new OracleParameter(":TTENURE", tenured));
        cmd.Parameters.Add(new OracleParameter(":TPHONE", phone));


       int i = cmd.ExecuteNonQuery();
       int k = commit.ExecuteNonQuery();

       MessageBox.Show(i + " rows affected");
       MessageBox.Show(k + " rows affected");


        conn.Close();

    }

Edit* the rest of the method to clear things up, and also, it is not throwing any errors, but does not update the database.

7
  • What is setting the values of the parameters your are using? Commented Apr 16, 2013 at 17:02
  • 1
    Exactly how is it not working: error message? Nothing updated? Commented Apr 16, 2013 at 17:10
  • My C# interface, this is a method being called from form1, the variables are correct because I've previously had it giving me a message box listing all of the parameters. Commented Apr 16, 2013 at 17:10
  • Sorry, nothing is updated, but no error message what so ever. Commented Apr 16, 2013 at 17:11
  • A long shot: what is your SSN data type in C#, and what is its data type in Oracle? Also, does the SSN in question have a leading zero? I've had trouble in the past dealing with the C# type being numeric (int, long, etc.) and the Oracle type being string (char, varchar2, etc.), or the other way around, and the trouble seems to intensify when the SSN has a leading zero or two. Commented Apr 16, 2013 at 17:42

1 Answer 1

1

Put the Parameters.Add in proper sequence. In your update query

"Update Teachers Set classroom_number = :TRM, Salary = :TSALARY, Tenured = :TTENURE, Phone_numer = :TPHONE Where SSN = :TSSN"

:TRM is occuring first and likewise. So keep the Parameters.Add also in same sequence. It will work. The sequence will be:

cmd.Parameters.Add(new OracleParameter(":TRM", Classroom));
cmd.Parameters.Add(new OracleParameter(":TSALARY", salary)); 
cmd.Parameters.Add(new OracleParameter(":TTENURE", tenured));
cmd.Parameters.Add(new OracleParameter(":TPHONE", phone));
cmd.Parameters.Add(new OracleParameter(":TSSN", SSN));    
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.