?
Solved

Jet/Access Query with Parameters on VS2010

Posted on 2011-09-08
2
Medium Priority
?
381 Views
Last Modified: 2012-06-27
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?
0
Comment
Question by:Thomasian
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 42

Accepted Solution

by:
dqmq earned 2000 total points
ID: 36507853
I believe it goes like this:


Parameters [Date] Date/Time;
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])
0
 
LVL 22

Author Closing Comment

by:Thomasian
ID: 36507934
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
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Suggested Courses
Course of the Month15 days, 15 hours left to enroll

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question