Display grid data by page

I have over 30,000 rows in a table. Gridview takes a lot of time to load all the data. So I want to display 100 lines at a time. When I click the button on the next page, another 100 lines should be displayed. When I click the button on the previous page, the previous 100 lines should be displayed. If I type page 5 in the text box, then I want to go to the 5th batch of lines.

I also want to show how many pages there will be. Can we implement this concept in gridview vb.net [winform]. I am using a PostgreSQL database.

Can someone give me a hint or some kind of concept?

0
source share
1 answer

See OFFSET and LIMIT in PostgreSQL.
Your request for page 5 may look like this:

SELECT * 
FROM   tbl
ORDER  BY id
OFFSET 400
LIMIT  100;

idis the main key in my example, so the index is in place automatically. If you access the table so much, performance can benefit from using CLUSTER .

Total Pages:

SELECT ceil(1235::real / 100)::int
FROM   tbl;

If you want the number to be rounded, simply simplify:

SELECT 1235  / 100
FROM   tbl;

If both numbers are integers, the result will be integer, and fractional digits will be truncated automatically. But I think you need to round here.

+1
source

Source: https://habr.com/ru/post/1648918/


All Articles