可以ODBC参数占位命名? [英] Can ODBC parameter place holders be named?

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

问题描述

我做了一些搜索,并没有发现一个明确的答案,我的问题。



有没有一种方法来定义哪些 在一个SQL查询所属的参数结果
为例,我需要这样的东西进行:

  SELECT * FROM myTable的WHERE MyField的= @参数1 OR myField2 = @参数1 
或myField1 = @参数2 OR myField2 = @参数2

ODBC 是:

  SELECT * FROM myTable的WHERE MyField的=?或myField2 =?或myField1 =? 
或myField2 =?



有没有办法告诉ODBC命令,它的参数是除了两次负载参数为每个值?



我怀疑有没有,但可以使用从有经验的程序员ODBC视角。




修改:我使用的ODBC驱动程序是一个BBJ ODBC驱动程序



。解决方案

在MSDN它明确指出,你不能说出这是告诉ODBC命令,它的参数是唯一的方法的参数。



虽然文件可以产生一些混乱:



从的 MSDN,OdbcParameter类




当CommandType设置为Text, .NET Framework数据提供ODBC不支持将命名参数到一个SQL语句或由一个名为的OdbcCommand的存储过程。在这两种情况下,使用问号(?)占位符。





的顺序OdbcParameter对象添加到OdbcParameterCollection必须直接对应于问号占位符在命令文本的参数的位置。




从以上这似乎表明,如果没有设置的CommandType为文本,也许你可以使用命名参数,但不幸的是你不能:



从的MSDN,OdbcCommand.CommandType物业的:




当CommandType属性设置为StoredProcedure时,应设置CommandText属性充分ODBC调用语法。然后,该命令执行时调用的Ex​​ecute方法(例如,的ExecuteReader或的ExecuteNonQuery)一个此存储过程。





.NET Framework数据提供程序的ODBC不支持将命名参数到一个SQL语句或由一个名为的OdbcCommand的存储过程。在这两种情况下,使用问号(?)占位符...



I did some searching and haven't found a definitive answer to my questions.

Is there a way to define which ? in a SQL query belongs to which parameter?
For example, I need to perform something like this:

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

The same query in ODBC is:

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

Is there a way to tell the ODBC command which parameter is which besides loading parameters in twice for each value?

I suspect there isn't but could use perspective from more experienced ODBC programmers.

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

解决方案

In MSDN it is explicitly stated that you cannot name the parameters which is the only way to "tell the ODBC command which parameter is which".

Although the documentation can generate a bit of confusion:

From 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.

From the above it seems to suggest that when CommandType is not set to Text maybe you can use named parameters, but unfortunately you can't:

From 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...

这篇关于可以ODBC参数占位命名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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