Link to home
Start Free TrialLog in
Avatar of Thomasian
ThomasianFlag for Philippines

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.
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)

Open in new window


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
Avatar of dqmq
dqmq
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Thomasian

ASKER

The 1st line ("Parameters...") is giving an error.

Enclosing the parameter names with []s works, but I have to manually add the parameters on the dataset.

Thanks