Board index » delphi » How do I return items 20 at a time from a query.

How do I return items 20 at a time from a query.

How would I structure a query in Delphi to return items 20 at a time?
I pretty much want to do it like a web page works where you see the
first 20 matches, then click next and see the next 20.  It seems to me
that I ought to be able to do it somehow with an SQL query, but the
documentation for SQL in delphi seems pretty sparse.

Thanks,
  Mike

 

Re:How do I return items 20 at a time from a query.


Quote
mehar...@students.wisc.edu (Mike Harper) wrote:

"How would I structure a query in Delphi to return items 20 at a time?
"I pretty much want to do it like a web page works where you see the
"first 20 matches, then click next and see the next 20.  It seems to me
"that I ought to be able to do it somehow with an SQL query, but the
"documentation for SQL in delphi seems pretty sparse.

SQL always gives you an entire result set, so if you limit it anyhow
as part of a "where ..." clause, there would be no next.

What you should do is build some standard looping construct in a
procedure you would call from the proper event-handlers, like:
        procedure UpdateScreenWithQueryResult(...);

        var Counter : byte;

        begin
         Counter := 1;
         while Counter <= 20 do      
          if not Query1.EOF then
           begin
                do something with the row;
                Query1.Next;
                Inc(Counter)
           else
                disable "NEXT"-button;
           end;
        end;

I hope this helps. Good luck!

Jasper

PS: please take into consideration
- when replying, I just think I know;
- when asking, be sure that I don't.

Other Threads