Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

From Db table to listview

Posted on 2004-04-21
5
Medium Priority
?
370 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 120 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

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…
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…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

618 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