OleDbCommand的参数顺序和优先级 [英] OleDbCommand parameters order and priority

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

问题描述

我一直在调试这个查询最后40分钟,这个问题显然是参数的顺序毕竟。

  SELECT * FROM tblSomeThing WHERE ID = @id和登场= @dtDebut和FIN​​ = @dtFin
 

然后,我添加的参数这种方式,请注意,最后两个参数进行切换,我没有得到任何结果。

  cmd.Parameters.Add(@ ID,OleDbType.Integer)。价值= idSociete;
cmd.Parameters.Add(@ dtFin,OleDbType.Date)。价值= dateTraitementFin;
cmd.Parameters.Add(@ dtDebut,OleDbType.Date)。价值= dateTraitementDebut;
 

当我声明参数出现在queury一切的方式完美地工作。

我还以为命名参数都在为解决这一问题放在第一位!什么我在这里丢失?

感谢您

解决方案

据<一href="http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbcommand.parameters.aspx">http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbcommand.parameters.aspx的OleDbCommand不支持命名的参数

  

的OLE DB .NET提供程序不支持命名的参数,将参数传递给SQL语句或存储过程调用一个OleDbCommand当CommandType设置为文本。在这种情况下,问号(?)占位符必须被使用。例如:

  SELECT * FROM客户WHERE客户id =?
 

  

因此​​,在这种OleDbParameter对象添加到OleDbParameterCollection的顺序必须直接对应问号占位符在命令文本的参数的位置。

于是命令的参数是非常重要的。

I have been debugging this query for the last 40 minutes, and the problem apparently is the order of the parameters after all.

SELECT * FROM tblSomeThing WHERE id = @id AND debut = @dtDebut AND fin = @dtFin

Then I add the parameters this way, notice that the two last parameters are switched, I get no results.

cmd.Parameters.Add("@id", OleDbType.Integer).Value = idSociete;
cmd.Parameters.Add("@dtFin", OleDbType.Date).Value = dateTraitementFin;
cmd.Parameters.Add("@dtDebut", OleDbType.Date).Value = dateTraitementDebut;

When I declare the parameters the way they appear in the queury everything works perfectly.

I thought named parameters were at first place to address this problem! what am I missing here?

Thank you

解决方案

According to http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbcommand.parameters.aspx OleDbCommand does not support named parameter

The OLE DB .NET Provider does not support named parameters for passing parameters to an SQL statement or a stored procedure called by an OleDbCommand when CommandType is set to Text. In this case, the question mark (?) placeholder must be used. For example:

SELECT * FROM Customers WHERE CustomerID = ?

Therefore, the order in which OleDbParameter objects are added to the OleDbParameterCollection must directly correspond to the position of the question mark placeholder for the parameter in the command text.

So order of parameter is important.

这篇关于OleDbCommand的参数顺序和优先级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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