Get oracle output parameter using OracleCommand

两盒软妹~` 提交于 2020-01-05 08:48:16

问题


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:


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!



来源:https://stackoverflow.com/questions/9494794/get-oracle-output-parameter-using-oraclecommand

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!