Welcome 微信登录

首页 / 网页编程 / ASP.NET / ASP.NET数据列表控件的分页总结(二)使用存储过程分页

ASP.NET数据列表控件的分页总结(二)使用存储过程分页2011-12-31 博客园 sl2008当数据库的数据量比较大,对执行效率要求比较高的时候,我们可以考虑使用存储过程来实现分页,根据传入的页数返回需要显示的数据表,仅仅select出当前页的数据。(这个比使用PagedDataSource类而言效率要高。)

现在采用Repeater来实现一个数据分页,数据库采用SQL server2000,利用里面的系统表Northwind。

新建存储过程如下:

create PROCEDURE dbo.myPaging(@pagesize int,@currentPage int,@total int output)AScreate table #temp( ID int identity(1,1), CustomerID varchar(50), CompanyName varchar(50), ContactName varchar(50), ContactTitle varchar(50), Phone varchar(50))insert into #temp(CustomerID,CompanyName,ContactName,ContactTitle,Phone)select CustomerID,CompanyName,ContactName,ContactTitle,Phonefrom Customersselect @total=(select count(*) from Customers)declare @startID intdeclare @endID intset @startID=(@currentpage-1)*@pagesize+1set @endID=@currentpage*@pagesizeselect * from #temp where ID>=@startID and ID<=@endIDGO
若不会写存储过程的话,可以参照网站在线生成分页的存储过程:http://www.webdiyer.com/AspNetPager/utility/sqlspgen.aspx