Solved

From Db table to listview

Posted on 2004-04-21
5
358 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

696 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