使用的OracleCommand遇到Oracle输出参数 [英] Get oracle output parameter using OracleCommand
问题描述
我有一个Oracle存储过程,该过程将返回一个值。我需要在我的C#程序的输出值。我需要知道我们如何可以使用OracleCommands AddWithValue方法得到的输出参数。
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.
我现在写的方法是:
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();
我知道如何OUTPUTPARAm我所说的是错误的。我怎样才能实现它使用
该的OracleCommand的AddWithValue方法。我不想用OracleCommands添加方法,我们还需要指定类型。
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.
推荐答案
请确保您在执行前设置的参数大小属性。在甲骨文输出参数,将指定大小充当缓冲器。如果没有设置缓冲区,它为0,因此不会从数据库中获取价值。
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;
剩下的就是好!
这篇关于使用的OracleCommand遇到Oracle输出参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!