有没有办法在C#中同时具有输入和输出的存储过程参数?

时间:2019-07-16 07:13:47

标签: c# sql sql-server

我正在重新编写一个用Delphi开发的程序,我想将其编码为C#。旧的开发人员使用了存储过程,我想像旧版本一样使用它。在SP的参数中,有一些输出参数,但其中之一也已用作输入参数。 因此,我必须为其设置一个值并获取输出值。

我试图这样编码:

int MyValue = 4;
SqlCommand MyCom = new SqlCommand();
MyCom.Connection = (SomeConnectionObject);
MyCom.CommandType = CommandType.StoredProcedure;
MyCom.CommandText = "MySP";

MyCom.Parameters.AddWithValue("@Parameter1_Output", MyValue);
MyCom.Parameters["@Parameter1_Output"].Direction = ParameterDirection.Output;

在我已将其设置为4的情况下,在执行查询(Profiler)中将其设置为0的值。

1 个答案:

答案 0 :(得分:2)

好吧,如果我们看看ParameterDirection enum,我们会发现

  

字段

     

...

     

InputOutput 3该参数能够同时输入和输出

(斜体是我的)。那就是为什么

MyCom.Parameters["@Parameter1_Output"].Direction = ParameterDirection.InputOutput;