c# - OleDbCommand 参数顺序和优先级

标签 c# ms-access ado.net oledb

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

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

然后我以这种方式添加参数,注意最后两个参数被调换了,我没有得到任何结果。

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

当我按照它们在查询中出现的方式声明参数时,一切正常。

我认为首先要解决这个问题的是命名参数!我在这里错过了什么?

谢谢

最佳答案

根据 http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbcommand.parameters.aspx OleDbCommand 不支持命名参数

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.

所以参数的顺序很重要。

关于c# - OleDbCommand 参数顺序和优先级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1476770/

相关文章:

c# - 数据转换失败。 [ OLE DB 状态值(如果已知)= 2 ]

c# - 使用 ServiceStack 创建 Json 数组

c# - CUDA 设备中的内存分配不是预期的

ms-access - 帮助进行 Access 中的日期查询

c# - 如何从数据列中获取数据

c# - 面向对象设计,交互对象

excel - 用于与 Excel 交互的 MS Access VBA 脚本

sql - 如何在第二个查询中使用第一个查询的结果?

.net - Entity Framework ObjectContext -> 对 native DBMS 的原始 SQL 调用

entity-framework - 如何在 Visual Studio 2010 中手动编辑 ADO.NET 中的表映射?