Solved

Easy way to search database for a name

Posted on 1998-08-10
4
216 Views
Last Modified: 2010-04-04
I'm using Delphi 3. Client/Server Suite.

1. I need answer to search database in the easy way / can you the Delphi expert help me!!!

2. Show me little code of using query with sql or paradox
0
Comment
Question by:vis
4 Comments
 
LVL 3

Expert Comment

by:vladika
ID: 1361821
There are many ways to search dataset for specific data.

1) Locate method
2) Lookup method
Locate finds the first row matching a specified set of criteria and moves the cursor
to that row.
Lookup returns values from the first row that matches a specified set of criteria,
but does not move the cursor to that row.

3) You can iterate through each record in the dataset and compare record with your criteria.

4) You can use Filter property to restrict dataset

5) You can use OnFilterRecord event to restrict dataset

6) You can use SQL and TQuery.
for example.
select * from customer where customer_name = 'Vladika'  :-)

maybe more ...

0
 
LVL 5

Expert Comment

by:mayhew
ID: 1361822
vladika's number 6 answer is probably the more common approach.

At least that's the way I'd do it.  :)

Let us know if you need more detailed instructions.
0
 
LVL 3

Expert Comment

by:rickpet
ID: 1361823
or number 7

7)
SQL property//you should never use * for your field names...
Select customer_id, last_name, first_name  
from Customer
where customer_id = :customer_id//this could be a like...

Params property set to integer for customer_id

in code...

with qryCustomer do begin
  Close;
  ParamByName('customer_id').AsInteger := MyValue;
  Open;

Rick

0
 
LVL 2

Accepted Solution

by:
saar071697 earned 200 total points
ID: 1361824
You can simply search the Ttable or Tquery Component to which the dbgrid is connected to.

Example:
Put a Dbgrid, TTable and a TDatasource on your form.
Connect  the dbgrid1 to the Datasource1 (dbgrid.datasource -property)
Connect the Datasource1 to Table1 (datasource.dataset-property)

Set TTable-databasename  and TTable-TabelName, and set
active to true.
Now put a Tedit control on the form and double-click it:
Then insert the folowwing  code:


procedure TForm1.Edit1Change(Sender: TObject);
begin
 Ttable1.Locate('FieldName',Edit1.Text,[]);
end;

If the Table is indexed you can also use findKey:

 Ttable1.FindKey([edit1.Text]);

greeting daniel
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

707 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

14 Experts available now in Live!

Get 1:1 Help Now