Solved

Jet/Access Query with Parameters on VS2010

Posted on 2011-09-08
2
348 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
2 Comments
 
LVL 42

Accepted Solution

by:
dqmq earned 500 total points
Comment Utility
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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
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 …

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now