如何使用命名参数在一个TableAdapter查询? [英] How to use named parameters in a TableAdapter query?
问题描述
我在配置通过查询向导的数据集。我想要生成的参数化查询。我的查询是这样的:
I am configuring a dataset through the query wizard. I want to generate the parametrized query. My query looks like this:
SELECT
Field1, Field2, Field3
FROM
SomeTable
WHERE
Field1 = @field1
数据被从Access中取出2007年数据库中,这个查询成功执行。从代码但是,我得到的错误:
The data is being fetched from an Access 2007 database, where this query executes successfully. From code however, I am getting the error:
错误WHERE子句附近的@。无法分析查询文本。
Error in WHERE clause near '@'. Unable to parse query text.
我该如何解决呢?
推荐答案
Access不支持命名的参数和使用?
而不是的@
( 。如SQL服务器)
Access doesn't support named parameters and uses ?
instead of @
(like SQL-Server).
所以这应该工作:
...
WHERE
Field1 = ?
在构造一个参数化查询,使用特定于您所编码对数据库参数注释。
When constructing a parameterized query, use the parameter notation specific to the database you are coding against.
例如,访问和OLEDB数据源使用问号?
来表示的参数,所以 WHERE
条款是这样的: WHERE市=
For example, Access and OleDb data sources use the question mark '?'
to denote parameters, so the WHERE
clause would look like this: WHERE City = ?
.
这篇关于如何使用命名参数在一个TableAdapter查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!