简体   繁体   English

C#-是否必须将参数添加到参数集合中

[英]C# -Do I have to add out parameter to parameters collection

I have a stored procedure that has an OUT parameter of type SYS_REFCUROR. 我有一个具有SYS_REFCUROR类型的OUT参数的存储过程。 From C# before executing the procedure I add all the parameters except for that OUT parameter. 在执行该过程之前,从C#中添加除OUT参数之外的所有参数。 But when I execute the procedure I get "wrong number or types of arguments " error. 但是,当我执行该过程时,出现“错误的参数数量或类型”错误。 My question is if I'm not going to assign any value to that parameter why do I have to add it to my parameters collection? 我的问题是,如果我不打算给该参数分配任何值,为什么我必须将其添加到我的参数集中?

You need to add out the parameter because after execution of the stored procedure, the value of out parameter of sql is stored in this out parameter you supplied in your code, which you can use later on in your further execution. 您需要添加该参数,因为在执行存储过程之后,sql的out参数的值存储在您在代码中提供的out参数中,您可以在以后的执行中使用该参数。

If you want to omit passing out the parameter, then assign a default value to the output parameter, that will resolve your issue. 如果要忽略传递参数,则为输出参数分配一个默认值,这将解决您的问题。

For example : 例如 :

CREATE PROCEDURE MyTest
   @Data1 int
   ,@Data3 int = null output 

If you do as above, then you don't need to pass the output parameter by code, and it will hide the error you are getting. 如果执行上述操作,则无需通过代码传递输出参数,这将隐藏您遇到的错误。

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

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