How to use named parameters in a TableAdapter query?

大城市里の小女人 提交于 2020-01-23 17:40:08

问题


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

The data is being fetched from an Access 2007 database, where this query executes successfully. From code however, I am getting the error:

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

How can I solve this?


回答1:


Access doesn't support named parameters and uses ? instead of @ (like SQL-Server).

So this should work:

...
WHERE
    Field1 = ?

See also 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 = ?.



来源:https://stackoverflow.com/questions/15270591/how-to-use-named-parameters-in-a-tableadapter-query

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!