省略的OleDbCommand命名的参数 [英] Omit named parameters from OleDbCommand

查看:111
本文介绍了省略的OleDbCommand命名的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的存储过程,这需要6 paramters。可以说,他们是 @a,@b,@c,@d,@e,@f ,他们都是可选的的默认值空



我需要知道如何调用存储过程是只有一些参数即可。我所知道的一般步骤:




  1. 定义的连接,并打开它


  2. 定义命令对象


  3. 参数添加到命令对象。


  4. 执行命令。




现在为每个 @a,@b ,@c,@d,@e,@f 我用 Parameters.Add()来添加参数。



的问题是:如果我要调用只有 @a @f ,我需要添加()其他参数也?或者,如果我补充一点,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 of null.

I need to know how to call the stored procedure with only some of these parameters. I know the general steps:

  1. Define a connection and Open it.

  2. Define a command object

  3. Add parameters to the command object.

  4. Execute the command.

Right now for each of @a, @b, @c, @d, @e, @f I use Parameters.Add() to add that parameter.

Question is: what if I want to call the stored procedure with just @a and @f, do I need to Add() 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆