Solved

From Db table to listview

Posted on 2004-04-21
5
345 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

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

16 Experts available now in Live!

Get 1:1 Help Now