简体   繁体   English

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

[英]Is there a way to have a stored procedure parameter that is both input and output in C#?

I'm re-writing a program which was developed in Delphi and I want to code it into C#. 我正在重新编写一个用Delphi开发的程序,我想将其编码为C#。 The old developer has used a stored procedure which I want to use it like the old version. 旧的开发人员使用了存储过程,我想像旧版本一样使用它。 In the SP's parameters, there are some output parameters but one of those in which has been used as an input parameter too. 在SP的参数中,有一些输出参数,但其中之一也已用作输入参数。 So I've to set a value to it and also get the output value. 因此,我必须为其设置一个值并获取输出值。

I tried to code like this: 我试图这样编码:

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;

In the executed query (Profiler) value set to the parameter is 0 while I have set it to 4. 在执行的查询(Profiler)中,设置为参数的值为0,而我将其设置为4。

Well, if we have a look at ParameterDirection enum we'll find 好吧,如果我们看一下ParameterDirection enum ,就会发现

Fields 领域

... ...

InputOutput 3 The parameter is capable of both input and output . InputOutput 3该参数可以输入和输出

(italic is mine). (斜体是我的)。 That's why 这就是为什么

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM