Nicolas
Nicolas

Reputation: 1171

Error defining query in visual studio with @ character

In Visual Studio 2010, I am using the wizard to create queries for TableAdapters. The query SELECT Modell FROM BHKW WHERE Energieträger = @Energieträger causes "Error around @ character" to appear (within the wizard). And this event though

  1. the @ and ä characters are allowed characters and
  2. this very simple query comes from an official Microsoft example (only the field names have been changed).

Does anybody know how to solve this problem?

Upvotes: 0

Views: 117

Answers (1)

Nicolas
Nicolas

Reputation: 1171

The wizard requires the use of square brackets for a SQL database. The correct query is then the following:

SELECT Modell FROM BHKW WHERE Energieträger = [@Energieträger]

If you use an Access database, the wizard will complete successfully but a warning will pop-up: "Returned data does not conform to the table's schema."

The correct syntax with an Access database requires a question mark:

SELECT Modell FROM BHKW WHERE (Energieträger = ?)

Upvotes: 1

Related Questions