Solved

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

Posted on 2007-04-03
3
244 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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks a lot. Simple answer and very useful...

regards
Lopem
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Our Group Policy work started with Small Business Server in 2000. Microsoft gave us an excellent OU and GPO model in subsequent SBS editions that utilized WMI filters, OU linking, and VBS scripts. These are some of experiences plus our spending a lo…
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…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

744 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

18 Experts available now in Live!

Get 1:1 Help Now