gpt4 book ai didi

c# - ODBC 参数占位符可以命名吗?

转载 作者:可可西里 更新时间:2023-11-01 07:55:32 25 4
gpt4 key购买 nike

我进行了一些搜索,但没有找到我的问题的明确答案。

有没有办法定义SQL查询中的哪个?属于哪个参数?
例如,我需要执行如下操作:

SELECT * FROM myTable WHERE myField = @Param1 OR myField2 = @Param1 
OR myField1 = @Param2 OR myField2 = @Param2

ODBC 中的相同查询是:

SELECT * FROM myTable WHERE myField = ? or myField2 = ? or myField1 = ? 
or myField2 = ?

除了为每个值加载两次参数之外,有没有办法告诉 ODBC 命令哪个参数是哪个?

我怀疑没有,但可以使用更有经验的 ODBC 程序员的观点。

EDIT : The ODBC driver I'm using is a BBj ODBC Driver.

最佳答案

在 MSDN 中明确指出您不能命名参数,这是“告诉 ODBC 命令哪个参数是哪个”的唯一方法。

虽然文档可能会产生一些困惑:

来自 MSDN, OdbcParameter Class :

When CommandType is set to Text, the .NET Framework Data Provider for ODBC does not support passing named parameters to an SQL statement or to a stored procedure called by an OdbcCommand. In either of these cases, use the question mark (?) placeholder.

The order in which OdbcParameter objects are added to the OdbcParameterCollection must directly correspond to the position of the question mark placeholder for the parameter in the command text.

从上面看来,当 CommandType 未设置为 Text 时,也许您可​​以使用命名参数,但遗憾的是您不能:

来自 MSDN, OdbcCommand.CommandType Property :

When the CommandType property is set to StoredProcedure, you should set the CommandText property to the full ODBC call syntax. The command then executes this stored procedure when you call one of the Execute methods (for example, ExecuteReader or ExecuteNonQuery).

The .NET Framework Data Provider for ODBC does not support passing named parameters to an SQL statement or to a stored procedure called by an OdbcCommand. In either of these cases, use the question mark (?) placeholder...

关于c# - ODBC 参数占位符可以命名吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6338139/

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