I’m trying to create a query in an access database for a C# dataset using the query editor but the created method says there is a problem and isn’t created correctly.
SELECT Discs.*
FROM Discs
WHERE (Title=@Title OR @Title IS NULL) AND
(Type=@Type OR @Type IS NULL) AND
(ContainerID=@ContainerID OR @ContainerID IS NULL) AND
NOT (@Title IS NULL AND @Type IS NULL AND @ContainerID IS NULL)
the error is:
Generated SELECT statement.
Error in WHERE clause near '@'.
Unable to parse query text.
the generated select method doesn’t have any parameters and is unusable.
I’ve tried the exact same SQL statement in the access query and it worked flawlessly, what am I supposed to be doing differently when transferring it to C#?
As far as I can remember (last time I tried, .NET 1.1 was the latest thing, so I’m not sure it’s the case), when you are talking to Jet OLEDB provider, you should signify parameters in the query with question marks (parameters are not named and the order matters):
(I’d wrap the identifiers in brackets so that they don’t cause problems should one of them be a keyword, you may try this before changing parameters to question marks)
Considering that your query uses the same parameters repeatedly, you probably have to add it more than once to the
Parameterscollection of yourOleDbCommandinstance.