I have a database with more than 2 million records and I need to perform a pagination to show on my web application, which must have 10 records per page in a DataGrid.
I already tryied to use ROW_NUMBER(), but this way will select all the 2 million records and then get only 10 records. I also tryied to use TOP 10, but I would have to save the first and last id to control the pages. And I’ve read that using DataAdapter.Fill() will select all the content and then get the 10 records that I need.
Which is the best way? Should I use DataAdapter.Fill()? Or use the SQL Server’s function ROW_NUMBER()? Or try to use TOP 10?
that is the query i am using for paging. use it and u will get ur desired 10 records in 4-5 seconds. i am getting 10 records in 3 seconds and total records in my db are 10 million, dont use top 10 it will only bring same 10 records everytime. in my case i am maintaining page size and starting row number (@FromRow) in the session and i pass these two values to the below given stored procedure and get the result.
Further more if you are using SQL 2012 you might want to use OFFSET and Fetch next 10 rows kind of thing. search on google about OFFSET keyword and you will see your desired result on top.
thanks