Solved

Easy way to search database for a name

Posted on 1998-08-10
4
217 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
A short film showing how OnPage and Connectwise integration works.

930 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