Parameterized query in Oracle trouble

前端 未结 6 892
走了就别回头了
走了就别回头了 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 03:00

    Try this, hope it works. It does compile.
    Not sure if you also have to send a commit...
    I always do this sort of thing through a stored procedure, so I have a commit after the update statement in the stored procedure.

    Harvey Sather

            OracleConnection ora_conn = new OracleConnection("connection string");
    
            OracleCommand ora_cmd = new OracleCommand("UPDATE db SET column1 = :param1 WHERE column2 = :param2", ora_conn);
            ora_cmd.CommandType = CommandType.Text;
            ora_cmd.BindByName = true;
    
            ora_cmd.Parameters.Add(":param1", OracleDbType.Varchar2, "1234", ParameterDirection.Input);
            ora_cmd.Parameters.Add(":param2", OracleDbType.Varchar2, "Y", ParameterDirection.Input);
    
            ora_cmd.ExecuteNonQuery();                
    

提交回复
热议问题