We help IT Professionals succeed at work.
Get Started

Using Filter option in TADOQuery

mudi_ji asked
Last Modified: 2008-02-01
i m facing a problem using filter option of TAdoQuery object. String in filters work fine but when i try to use filter on dates, it throws an exception.
i m trying to fetch records from database using TADOQuery object and then applying filters at runtime. Problem occurs when i apply filter on date column. i have a table named orders, and there is a column orderDate. Now when i need to apply filter to get orders between two given dates, i do following steps;

qryOrders.filter := 'OrderDate between ''' + DateToStr(dtPkr1.Date) + ''' and ''' + DateToStr(dtPkr2.Date) + '''';
qryOrders.filtered := true;

when code executes, following EOleException is thrown:
"Arguments are of wrong type, are out of acceptable range or are in conflict with one another"

now thats right as i m converting date to string in filter and actual column is of datatype datetime, but i need to do so as filter accepts only strings. i also tried using # character instead of using quotes to enclose date in, (as in case of crystal reports) but it again gives same error.
can anyone help me plz ?
Watch Question
This problem has been solved!
Unlock 1 Answer and 9 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE