Link to home
Start Free TrialLog in
Avatar of s_monani
s_monani

asked on

ADO Recordset Filter using IN Clause

Hi
I am using Microsoft ADO Object library 2.5 in my Visual Basic project. I am facing the problem using filter method when i am specifying IN clause. If ADO filter supports IN clause then can u please send some examples.

   my code is something like this:
   
    rs.Filter = "ID in (22,23,25)"

where ID is number field.

Avatar of Bob Lamberson
Bob Lamberson
Flag of United States of America image

rs.Filter = "(((ID)=22 Or (ID)=23 Or (ID)=24))"

Bob
Avatar of s_monani
s_monani

ASKER

The list which i want to compare is very long. Not possible with an OR operator which is y i want to use an IN clause
Avatar of Dirk Haest
Perhaps you should consider then closing your recordset and rebuild the sql-query

rs.close
strSql = "Select * from YourTable where ID in (22,23,25)"
rs.Open strSql, YourConnection, adOpenDynamic, adLockPessimistic
I dont want a where clause. i want to incorporate IN clause using recordset.filter
ASKER CERTIFIED SOLUTION
Avatar of _lv_
_lv_
Flag of Lithuania 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
Mine and Dhaest are the only two options. I would use Dhaest's idea. The filter option is slow by comparison to the sql option. especially if you have a lot of conditions.
Is there some reason you are not stating that you don't want to use the sql method?

Bob