Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extracting data from tables and displaying it in a listview

Status
Not open for further replies.

sanjna000

Programmer
Aug 1, 2003
132
GB
Hi,

I 've got 2 tables. The stucture of each table as follows:

ModuleName

ID - PK
Name

ModuleVersion

ID -PK
TblModuleName_ID
TblNote_ID
ModuleNumber

When i select a particular NoteID from the combo box available in the main form , it should show the relevant module name along with the module number in a listview.

the code i used is as below:

ListView.Clear;
With qryGeneral Do
Begin
SQL.Clear;
SQL.Add( 'SELECT ( a1.Name, a2.ModuleNumber )' );
SQL.Add( ' FROM TblModuleName a1, TblModuleVersion a2 ' );
SQL.Add( ' WHERE ( TblNote_ID="' + CB_RNo.Text + '") And ( a1.ID = a2.TblModuleName_ID) ' );
Open;
For i:= 1 to RecordCount Do
Begin
ListView.AddItem( ( FieldByName( 'ModuleNumber'). AsString ), nil);
ListView.Items.SubItems.Add(FieldByName('Name').
AsString );
Next;
End;
Close;

This caused an exception error. This is the first time i am using alias and i guess i am doing something terribly wrong. Can anyone help me out ...

Thank you sooooo much for u r help in advance.

Sanjna...
 
First:
Is your query working properly ?
Check the data with a dbgrid.

Second:
i must start with 0
what will happen if the query is empty?
..endless loop

Steven van Els
SAvanEls@cq-link.sr
 
small codechange following svanels recommendations :

ListView.Clear;
With qryGeneral Do
Begin
SQL.Clear;
SQL.Add( 'SELECT ( a1.Name, a2.ModuleNumber )' );
SQL.Add( ' FROM TblModuleName a1, TblModuleVersion a2 ' );
SQL.Add( ' WHERE ( TblNote_ID="' + CB_RNo.Text + '") And ( a1.ID = a2.TblModuleName_ID) ' );
Open;
while not EOF Do
Begin
ListView.AddItem( ( FieldByName( 'ModuleNumber'). AsString ), nil);
ListView.Items.SubItems.Add(FieldByName('Name').
AsString );
Next;
End;
Close;


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top