Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jul 2007
    Location
    Velsen Noord, Netherlands
    Posts
    206
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Add records from adoquery to listbox

    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.
    Code:
    procedure TForm1.Button2Click(Sender: TObject);
    begin
      DBListBox1.Items.Clear;
      DBListBox1.Items.Add(ADQuery1.FieldByName('songtitle').AsString);
    end;

  • #2
    New to the CF scene
    Join Date
    Sep 2009
    Location
    Panama
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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...):
    Code:
    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;

  • #3
    Regular Coder
    Join Date
    Jul 2007
    Location
    Velsen Noord, Netherlands
    Posts
    206
    Thanks
    6
    Thanked 0 Times in 0 Posts
    My bad, I already solved it, but forgot to say.

    This is how I solved it:
    Code:
    procedure TForm1.Button2Click(Sender: TObject);
    begin
    ListBox1.Items.Add(ADQuery1.FieldByName('songtitle').AsString);
    end;


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •