Search code examples
delphitadoquery

(Delphi) query.next not working


I need help to fix my code...

I try to build some application with this code

Adoquery.close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('select * from schedule where every like ''%5%''');
ADOQuery1.Open;

if not ADOQuery1.Eof then
  begin
  ShowMessage('hallo '+ADOQuery1.fieldbyname('remark').AsString);
  ADOQuery1.Next;
  end
Else
  Begin
  end;

I have 2 data records for the result, but why only one remark is showing?

I try to Trace it and found problem in ADOQuery1.next. After my application read ADOQuery.next, cursor jump to

end;
not go back to
if not ADOQuery1.Eof then
.

Any mistakes with my code?


Solution

  • The execution does not go back to the if statement because the code does not say to do so. You have a single if statement and no iteration. You need to iterate. For instance with a while loop:

    while not ADOQuery1.Eof do begin
      // do something
      ADOQuery1.Next;
    end;