2

I have a query in ADOQuery2. Now I want have a filter for that so:

  ADOQuery2.Filter := 'where Fname like ' + QuotedStr(Txt_Search.Text + '*');
  ADOQuery2.Filtered := true;

but it throws this exception: (* in like statement is for Access instead of %)

enter image description here

any idea?

0

2 Answers 2

4

When using the LIKE operator from within Access itself the asterisk * is the correct wildcard character, but for ADO connections from other applications (like yours) you should actually be using the "standard" percent % wildcard character for SQL.

1
  • aaaah thanks for this. as usual, I should have asked google/stack overflow way sooner, but nooo, it takes me at least an hour to 'admit that I need help'... Jul 15, 2013 at 14:52
0

Try this, it works fine

if  Txt_Search.Text<> '' then
begin
    ADOQuery2.Filter := 'where Fname like '+QuotedStr(Txt_Search.Text+'*');
    ADOQuery2.Filtered := true;
end;

or

if  Txt_Search.Text<> '' then
begin
    ADOQuery2.Filter := 'Fname like '+QuotedStr(Txt_Search.Text+'%');
    ADOQuery2.Filtered := true;
end;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.