0

我在 C# 中遇到更新查询问题。对我来说很奇怪,我在更新时遇到问题,但是选择、删除和插入工作。

  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();

    }

编辑*其余的方法来清除事情,而且,它不会抛出任何错误,但不会更新数据库。

4

1 回答 1

1

将Parameters.Add按正确的顺序放置。在您的更新查询中

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

:TRM 首先发生,同样如此。所以保持Parameters.Add也以相同的顺序。它会起作用的。顺序将是:

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));    
于 2013-10-23T09:04:59.300 回答