...

View Full Version : Add records from adoquery to listbox



UD2006
08-28-2009, 11:35 PM
I want to add records from an adoquery, with dbgrid (online database) into a listbox. The records in the adoquery have 1 column (songtitle).

I managed to get 1 record into the listbox, but when I try to add another one, the first one is replaced, how can I put the next records after the 1 one (not replacing it)?

This is the code I use to copy the record from adoquery1 to listbox1.


procedure TForm1.Button2Click(Sender: TObject);
begin
DBListBox1.Items.Clear;
DBListBox1.Items.Add(ADQuery1.FieldByName('songtitle').AsString);
end;

everweb
09-04-2009, 09:01 PM
What language is that, delphi/pascal ?
Try the following (I've never used delphi and I don't use Windows so there may be errors...):


procedure TForm1.Button2Click(Sender: TObject);
begin
DBListBox1.Items.Clear;
ADQuery1.First;
for a:=1 to ADQuery1.RecordCount do
begin
DBListBox1.Items.Add(ADQuery1.FieldByName('songtitle').AsString);
ADQuery1.Next;
end;
end;

UD2006
09-04-2009, 09:26 PM
My bad, I already solved it, but forgot to say.

This is how I solved it:


procedure TForm1.Button2Click(Sender: TObject);
begin
ListBox1.Items.Add(ADQuery1.FieldByName('songtitle').AsString);
end;



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum