10.8. Improving Paging Performance
Problem
Given an application that allows the user to page through a large result set in a data grid, you need to improve the performance of the paging.
Solution
Build a custom paging solution that overcomes the performance limitations of the overloaded Fill() method of the DataAdapter.
The solution uses a single stored procedure, which is shown in Example 10-12.
Page_ContactUsed to return 10 records from the
Orderstable of theNorthwinddatabase that correspond the first, last, next, or previous page, or a specific page. The procedure has the following arguments:@PageCommandAn input parameter that accepts one of the following values:
FIRST, LAST, PREVIOUS, NEXT, orGOTO. This specifies the page of results to return to the client.@FirstContactIDAn input parameter that contains the
ContactIDof the first record of the client's current page ofContactdata.@LastContactIDAn input parameter that contains the
ContactIDof the last record of the client's current page ofOrdersdata.@PageCountAn output parameter that returns the number of pages, each of which contains 10 records, in the result set.
@CurrentPageAn output parameter that returns the page number of the result set returned.
Example 10-12. Stored procedure: Page_Contact
USE AdventureWorks GO CREATE PROCEDURE Page_Contact @PageCommand nvarchar(10), @FirstContactID int = null, @LastContactID int = null, @PageCount int output, @CurrentPage int output AS SET NOCOUNT ON SELECT @PageCount = CEILING(COUNT(*)/10) ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access