Solved

From Db table to listview

Posted on 2004-04-21
5
352 Views
Last Modified: 2010-04-05
i have database table (Firebird) Consist of the following Fields
Emp _table :
Id
name
Salary
Age
   Iwant Code to Select all employee whitch in specific age and Add them To listview whitch is Vsreport view Style
and the columns are Same in database?
0
Comment
Question by:sraab2004
  • 3
5 Comments
 
LVL 3

Expert Comment

by:MikProg
ID: 10886016
use TQuery descendants to excute 'select * from Emp where age=..'
add Q.Fields.Count-1 columns to you listview
then simply
Q.First;
while not Q.eof do
begin
  with listview.Items.Add, Q.Fields do
  begin
    Caption:=FieldByName('Id').AsString;
    subitems.add(FieldByName('Name').AsString);
    subitems.add(FieldByName('Salary').AsString);
    subitems.add(FieldByName('Age').AsString);
  end;
end;

0
 
LVL 11

Accepted Solution

by:
shaneholmes earned 40 total points
ID: 10888373
sraab2004,

Here is a more descriptive example.... (and MikProg forgot his call to NEXT in his iteration).

Create a Query using parameters (passing it the Age)

Example:

 Query1.Close;
 Query1.SQL.Clear;
 Query1.sql.text:='Select * from Employee where Age=:AAge'
 Query1.parambyname('AAge').asInteger:= 21;
 Query1.Open

Now iterate through the returned set, populating your ListView with the Records...


Query1.First;
while not Query1.eof do
begin
 Item:=   ListView1.Items.Add;
 Item.Caption:= Query1.FieldByName('Id').AsString;
 Item.SubItems.Add(Query1.FieldByName('Name').AsString);
 Item.SubItems.Add(Query1.FieldByName('Salary').AsString);
 Item.SubItems.Add(Query1.FieldByName('Age').AsString);
  end;
 Query1.Next;  //******* this is key - do not forget this
end;


Shane
0
 
LVL 3

Expert Comment

by:MikProg
ID: 10888705
Oooooh! oooooh ! OOOOOOOOOh! I forgot Q.Next! Bye bye my points! AAAAAA! :)
0
 

Author Comment

by:sraab2004
ID: 10906676
query1.next must be inside while loop shane I want to divide the points between shane (20) and mikprog (10) how to do that ?
0
 
LVL 3

Expert Comment

by:MikProg
ID: 10916488
Don't care about points! I'm really loose them.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

777 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