Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi search in database (https://www.delphipraxis.net/96313-search-database.html)

mohfa 22. Jul 2007 11:03


search in database
 
i really need your help in this :

i have table contains 3 fields :
1st Field : Id ( integer )
2nd Field : Categ ( string )
3rd Field : Name ( String )

i'd like to seach the 3rd Field for a string , if the result is True then
Display the result in a TListView like this :
ID | Categ | Name


i did it like this
Delphi-Quellcode:
ListView.Items.Clear;
if Found then // yes we find the searched word

begin

  With MyTable do
  begin
      Close;
 
      Open;
      first;
    while not EOF do
   begin
     ListView1.Items.AddItem(nil);
     ListView1.Items[ListView1.Items.Count-1].Caption := FieldByName('ID').AsString;  
     ListView1.Items[ListView1.Items.Count-1].SubItems.Add(FieldByName('Categ').AsString);
     Next;
     end;

the problem here is that all records will be displayed , But i want only the found record to be displayed.


thanks

mkinzler 22. Jul 2007 11:05

Re: search in database
 
Have you tried .Filter ?
Or even better to switch to TQuery

mohfa 22. Jul 2007 11:14

Re: search in database
 
ok mkinzler
how can we do that with TQuery


thank

mkinzler 22. Jul 2007 11:23

Re: search in database
 
Delphi-Quellcode:
.Sql.Text := 'select * from <Table> where <Field3> like + QuotedStr( '%'+strtobefound+'%')+';';


Alle Zeitangaben in WEZ +1. Es ist jetzt 10:34 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz