省略的OleDbCommand命名的参数 [英] Omit named parameters from OleDbCommand
问题描述
我有一个简单的存储过程,这需要6 paramters。可以说,他们是 @a,@b,@c,@d,@e,@f
,他们都是可选的的默认值空
。
我需要知道如何调用存储过程是只有一些参数即可。我所知道的一般步骤:
-
定义的连接,并打开它
-
定义命令对象
-
参数添加到命令对象。
-
执行命令。
现在为每个 @a,@b ,@c,@d,@e,@f
我用 Parameters.Add()
来添加参数。
的问题是:如果我要调用只有 @a
和 @f $存储过程C $ C>,我需要
添加()
其他参数也?或者,如果我补充一点,2个参数如何将存储过程知道哪些参数我提供?
问题是:如果我想@a和@f调用存储过程只用
块引用>
只要其他都是可选的SP没有任何错误将被执行。
在反正这种情况下,我还需要添加其他参数(b,C,D,E) ?
块引用>
没有,你不知道。
如果我加2只参数的存储过程是怎么知道的顺序?
块引用>
订单在这里并不重要。参数名。它以匹配SP申报之一。
I have a Simple stored procedure which takes 6 paramters. Lets say they are
@a, @b, @c, @d, @e, @f
and they are all optional with the default value ofnull
.I need to know how to call the stored procedure with only some of these parameters. I know the general steps:
Define a connection and Open it.
Define a command object
Add parameters to the command object.
Execute the command.
Right now for each of
@a, @b, @c, @d, @e, @f
I useParameters.Add()
to add that parameter.Question is: what if I want to call the stored procedure with just
@a
and@f
, do I need toAdd()
the other parameters also? Or if I add just 2 parameters how will the stored procedure know which parameters I supplied?解决方案Question is :What if I want to call the stored procedure with just @a and @f,
As long as other are optional SP will be executed without any errors.
In this case do I need to Add other parameters also (b,c,d,e) anyway?
No, you don't.
If I add just 2 parameters how stored procedure knows the order?
Order is not important here. The parameter name is. It has to match the one from SP declaration.
这篇关于省略的OleDbCommand命名的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!