Jesus Zamora Jesus Zamora - 2 months ago 13
C# Question

How to return oracle output parameters from a stored procedure in .NET

I am having serious issues trying to get the data back from the SP. I was trying to do it like this:

OracleCommand ora_cmd = new OracleCommand("a6r1.PR_ABC_P_ALTA_TARJETA_PAYWARE", ora_conn);
ora_cmd.BindByName = true;
ora_cmd.CommandType = CommandType.StoredProcedure;

int success= new int();

ora_cmd.Parameters.Add("Lc_Param_Issuer", OracleDbType.Varchar2, issuer, ParameterDirection.Input);
ora_cmd.Parameters.Add("Ln_Param_Valid_Product", OracleDbType.Varchar2, DropDownListProducto.SelectedValue.ToString(), ParameterDirection.Input);
ora_cmd.Parameters.Add("Ln_Param_Total", OracleDbType.Int32, parsed, ParameterDirection.Input);
ora_cmd.Parameters.Add("Lc_Param_User", OracleDbType.Varchar2, user, ParameterDirection.Input);
ora_cmd.Parameters.Add("Lc_Encrypted_Password", OracleDbType.Varchar2, pass, ParameterDirection.Input);
ora_cmd.Parameters.Add("Lc_Exito", OracleDbType.Int32, success, ParameterDirection.Output);
ora_cmd.Parameters.Add("Lc_Error", OracleDbType.Varchar2, errorMessage, ParameterDirection.Output);


But it is not returning anything to the variables sucess or errorMessage. What am I doing wrong? Is there a better way? It works fine when executed directly on Oracle.

Answer

It seems you cannot use existing variable as output parameter, try this way instead

ora_cmd.Parameters.Add("Lc_Exito", OracleDbType.Int32).Direction = ParameterDirection.Output;

ora_cmd.ExecuteNonQuery();

if (ora_cmd.Parameters["Lc_Exito"].value == 0)