1

I have a oracle stored procedure which will return a value. I need to get the OUTPUT value in my C# program. I need to know how we can get the OUTPUT parameter using the OracleCommands AddWithValue method.

The way i have written now is:

 OracleCommand Ocmd = new OracleCommand(_StoredProcedure, OraCon);
    Ocmd.CommandType = CommandType.StoredProcedure;


            Ocmd.Parameters.AddWithValue("Filed1", "Value1");

            Ocmd.Parameters.AddWithValue("OUTPUTParam","").Direction = ParameterDirection.Output;

    OraCon.Open();
    int RecivedDetID = Ocmd.ExecuteNonQuery();
    OraCon.Close();

    return Ocmd.Parameters[_OutParam].Value.ToString();

I know the OUTPUTPARAm how i have called is wrong. How can i achieve it using the AddWithValue method of the OracleCommand. I dont want to use the OracleCommands Add method where we need to specify the Type also.

1 Answer 1

7

Make sure you set the SIZE property on the parameter before executing. With output parameters in Oracle, the specified size acts as a buffer. If the buffer isn't set, it is 0 so you don't get the value from the database.

var param = Ocmd.Parameters.AddWithValue("OUTPUTParam","").Direction = ParameterDirection.Output;
param.Size = 255;

The rest is good!

Sign up to request clarification or add additional context in comments.

2 Comments

Which version of the OracleDataAccess are you using?
I mean as far as 10g/11g. The version this works in is 10.2.0.100 or higher. Also, are you using the .net 1.x or 2.x assemblies? you can find this information by right clicking on the Reference in the project and clicking properties.

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.