0

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?

Sunil Garg
  • 14,608
  • 25
  • 132
  • 189
Gigih Arie
  • 13
  • 2
  • 4
    You should use a `while` like `while not ADOQuery1.Eof do` – RRUZ Mar 16 '17 at 05:55
  • Additional, you should also make your cursor to be on the first record before iterating like this `ADOQuery1.First;` – Alec Mar 16 '17 at 08:18
  • 2
    @Fero68, yes that is a good habit to get into, but unnecessary immediately after a call to `Open`. – MartynA Mar 16 '17 at 08:55

1 Answers1

4

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;
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490