In this article you learn how to fetch data according PageIndex and PageSize. In web application, it is much more important to
increase webform performance, loadbalance.
In my development experience, some of table hold large
amount of records (more than 2GB) and user need to shows records in GridView.
But problem is when we select all records and loads in webforms, webform has crashed.
In that case, I will simply solved with Table Variable and
using Grid Page Number and Page Size.
1. Create Procedure
CREATE PROCEDURE Load_Data_WithPaging @PageIndex AS INT, /*Selected Row Index of selected grid*/ @PageSize AS INT, /*Total page size of selected grid*/ @TotalRecords AS INT OUT /*used for display virtual page no*/ AS BEGIN SET NOCOUNT ON; DECLARE @FromIndex AS INT = 0, @ToIndex AS INT = 0; SET @FromIndex = (@PageIndex * @PageSize) + 1; /*First row no selection*/ SET @ToIndex = ((@PageIndex * @PageSize) + @PageSize);/*Last row no selection*/ SET @TotalRecords = 0; /*Temp Table */ DECLARE @TempTrans TABLE ( SerialNumber INT, Id INT, AgentId INT, EntryDate DATETIME, TransactionCode VARCHAR(50), CustomerId INT, FromCurrencyId INT, SendAmount DECIMAL(20, 4), ToCurrencyId INT ); INSERT INTO @TempTrans SELECT row_number() over (order by MT.EntryDate DESC) AS SerialNumber , MT.Id, MT.AgentId, MT.EntryDate , MT.TransactionCode, MT.CustomerId , MT.FromCurrencyId, MT.SendAmount , MT.ToCurrencyId FROM dbo.Mtr_MoneyTransfer MT ORDER BY MT.Id DESC SELECT * FROM @TempTrans WHERE SerialNumber BETWEEN @FromIndex AND @ToIndex SELECT @TotalRecords = COUNT(*) FROM @TempTrans END;
Second page:
DECLARE @TotalRecords AS INT EXEC Load_Data_WithPaging 1, 10, @TotalRecords out SELECT @TotalRecords
Comments
Post a Comment