2013-03-07 67 views
1

我正在通过查询向导配置数据集。我想要生成参数化查询。我的查询如下所示:如何在TableAdapter查询中使用命名参数?

SELECT 
    Field1, Field2, Field3 
FROM 
    SomeTable 
WHERE 
    Field1 = @field1 

正在从Access 2007数据库中提取数据,其中此查询成功执行。从代码然而,我得到错误:

Error in WHERE clause near '@'. Unable to parse query text.

我该如何解决这个问题?

+0

我告诉aboutTableAdapter配置向导。顺便说一下,你可以看到[查询](http://i.imgur.com/MJ3IeBs.png)和[错误](http://i.imgur.com/HBzvZJO.png“)@Tim Schmelter – 2013-03-07 12:14:49

回答

2

访问不支持命名参数,并使用?而不是@(如SQL-Server)。

所以这应该工作:

... 
WHERE 
    Field1 = ? 

How to: Create Parameterized TableAdapter Queries参见:

When constructing a parameterized query, use the parameter notation specific to the database you are coding against.

For example, Access and OleDb data sources use the question mark '?' to denote parameters, so the WHERE clause would look like this: WHERE City = ? .

+0

谢谢你太多了,先生,@Tim Schmelter,它工作完美。 – 2013-03-07 12:22:56