Get oracle output parameter using OracleCommand

I have an oracle stored procedure that 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.

Now I wrote:

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 that OUTPUTPARAm, as I called, is wrong. How can I achieve this using the AddWithValue of the OracleCommand method. I do not want to use the OracleCommands Add method, where we need to also specify Type.

+1
oracle system.data.oracleclient
source share
1 answer

Before you run, make sure you set the SIZE property for the parameter. With output parameters in Oracle, the specified size acts as a buffer. If the buffer is not set, it is 0, so you will not get the value from the database.

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

The rest is good!

+4
source share

All Articles