Solved

Easy way to search database for a name

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Machine not responding during CopyFile() 3 104
Controlled Assessment GCSE - desperate help needed 4 102
creating threads in delphi 1 131
Firemonkey webbrowser scrollbars ? 1 50
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

856 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