Thomasian
asked on
Jet/Access Query with Parameters on VS2010
In SQL Server, I can create a dataset with parameters by using the prefix @
e.g.
I can then access the parameters using the parameter name "Date".
Now I need to make this work with Jet/Access DB as backend. It seems that it does not recognize @ as a prefix for a parameter since it give an error "Error in WHERE clause near '@'". I googled a little and found that jet uses "?" to specify a parameter but the problem is replacing both @Date from the query with ? will create 2 parameters.
What is the 'correct' way to create a parameterized query in a dataset for Jet?
e.g.
SELECT *
FROM
(Table1 As T LEFT JOIN
Table2 As C ON T.CodeID=C.CodeID) LEFT JOIN
Table3 As U ON T.UserID=U.UserID
WHERE
T.TimeIn >= @Date
AND T.TimeIn < DateAdd("n",1,@Date)
I can then access the parameters using the parameter name "Date".
Now I need to make this work with Jet/Access DB as backend. It seems that it does not recognize @ as a prefix for a parameter since it give an error "Error in WHERE clause near '@'". I googled a little and found that jet uses "?" to specify a parameter but the problem is replacing both @Date from the query with ? will create 2 parameters.
What is the 'correct' way to create a parameterized query in a dataset for Jet?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Enclosing the parameter names with []s works, but I have to manually add the parameters on the dataset.
Thanks