Solved

how to search (filter) substrings using a query component in a BDE database?

Posted on 2007-04-03
3
247 Views
Last Modified: 2010-04-05
I have a BDE database with three fields: two memos and one string field. I want to searchand filter  the string field to find partial strings. I mean, I want to filter the database (and to see the results in a dbgrid who is present in my form) if I search for the string "nd". The system should show me the records with this specific field 'nd', for instance 'random' or 'and', but hide records with 'hello' string...

I tried this:

   Query1.Active:=false;
    Query1.Sql.Clear;
    Query1.Sql.Add('select * from database where field like '+QuotedStr('%'+SearchStr+'%'));
    Query1.Active:=true;

but it didnt work...Any ideas what I am doing wrong? Should I have the string field indexed?
0
Comment
Question by:lopem
3 Comments
 
LVL 17

Accepted Solution

by:
TheRealLoki earned 50 total points
ID: 18848728
normally in SQL you can use "like" as in
select * from table1 where FirstName like '%something%'
the % being a wildcard
However, I don't think BDE supports this.
You could however, use the "OnFilter" event.
set the "filtered" property to true and then in the onfilter event you use
Accept := (pos(edit1.text, dataset.FieldByName('SomeField').AsString > 0);
0
 
LVL 6

Expert Comment

by:bokist
ID: 18848999
Hi !
Try this way:
       with Query do
          begin
          Close;
          Sql.Clear;
          Sql.add('select * from database where field like :p');
          Parambyname('p').asstring := '%' +SearchStr+ '%';
          Open;
       end;

Steve
0
 
LVL 3

Author Comment

by:lopem
ID: 18851494
Thanks a lot. Simple answer and very useful...

regards
Lopem
0

Featured Post

The curse of the end user strikes again      

You’ve updated all your end user’s email signatures. Hooray! But guess what? They’re playing around with the HTML, adding stupid taglines and ruining the imagery. Find out how you can save your signatures from end users today.

Question has a verified solution.

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

Suggested Solutions

Storage devices are generally used to save the data or sometime transfer the data from one computer system to another system. However, sometimes user accidentally erased their important data from the Storage devices. Users have to know how data reco…
If you get continual lockouts after changing your Active Directory password, there are several possible reasons.  Two of the most common are using other devices to access your email and stored passwords in the credential manager of windows.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

911 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

20 Experts available now in Live!

Get 1:1 Help Now