gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 03:06:09 26 4
gpt4 key购买 nike

过去 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com