Solved

From Db table to listview

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

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