Parameterized query in Oracle trouble

前端 未结 6 907
走了就别回头了
走了就别回头了 2020-12-10 02:14

I\'m using Oracle.DataAccess rather than the obsolete System.Data.OracleClient and I seem to be having trouble passing multiple parameters to my up

6条回答
  •  情书的邮戳
    2020-12-10 02:56

    Here's the type of structure I usually use (sorry, this is from memory) :

    int rows = 0;
    using ( OracleConnection conn = new OracleConnection(connectionString) ) {
      using ( OracleCommand cmd = conn.CreateCommand() ) {
        cmd.CommandText = "UPDATE table SET column1 = ':p1 WHERE column2 = :p2";
        cmd.CommandType = CommandType.Text;
        cmd.Parameters.AddWithValue(":p1", p1Val);
        cmd.Parameters.AddWithValue(":p2", p2Val);
        rows = cmd.ExecuteNonQuery();
      }
    }
    

    The key difference is the use of the AddWithValue - I don`t remember why I ended up using that, but do remember having problems with some of the other ways of doing it.

提交回复
热议问题