All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
轻量级的Ajax解决方案——DynAjax的JQuery版_[AJAX教程]
C#中实现VB中的CreateObject方法_.net资料_编程技术
初学,ASP.NET,AJAX,(四):Timer,和,UpdateProgress_[Asp.Net教程]
GridView,中,DropDownList,弹出确认对话框_[Asp.Net教程]
C#中goto语句的使用方法
.NET,2.0,SqlDependency快速上手指南_[Asp.Net教程]
C#中实现随机时间的获取_.net资料_编程技术
vs2005视频教程之自定义服务器控件(下)[视频]_[Asp.Net教程]
ASP.NET,MVC+LINQ开发一个图书销售站点(7)-图书分类管理_[Asp.Net教程]
缺陷月项目启动,披露PHP脚本语言漏洞_php资料_编程技术
Reading number is top 10 pictures
Photographed the passion of the clients and prostitutes in the sex trade picture1
Fury xp desktop theme
Ashlynn Brooke show proud chest measurement1
超强高考作文
Ashlynn Brooke photograph of a group3
到南昌西站了2
大四女生借债隆胸成功
A man's favorite things15
The real super beauty13
一万二一支的万珂,用得真心肉疼。
Download software ranking
好色的外科大夫
艳兽都市
C语言教程TXT
linux高级编程
Visual C++界面编程技术
Boxer Classic video1
Boxer's Top ten classic battle1
Tram sex maniac 2 (H) rar bag2
Boxer Classic video3
Love the forty days
aaa published in(发表于) 2013/12/8 7:50:55 Edit(编辑)
ASP.NET技巧:在存储过程中实现分页_.net资料_编程技术

ASP.NET技巧:在存储过程中实现分页_.net资料_编程技术

ASP.NET技巧:在存储过程中实现分页_.net资料_编程技术-你的首页-uuhomepage.com
我不是一个很有经验的程序员,在做项目的过程中会遇到很多的问题,在数据库中使用分页就是我做项目中遇到的一个问题.我从网上查了很多资料,有很多种方法.但我觉的创建临时数据表是最简单的方法,在我做Membership扩展时发现原来微软也是这样用的,你可一随便打开一个Membership的存储过程看看.
说了再多也没用,只要看看代码就清楚了,呵呵.

1CREATE PROCEDURE dbo.CreateSimple
2(
3 @PageIndex int,
4 @PageSize int
5)
6AS
7BEGIN
8 --定义三个变量:
9 -- @PageLowerBound :所取出记录的下限.
10 -- @PageUpperBound: 所要取出记录的上限.
11 -- @TotalRecords: 返回记录总数,主要用于页面的计算.
12 DECLARE @PageLowerBound int
13 DECLARE @PageUpperBound int
14 DECLARE @TotalRecords int
15
16 --计算上下限的值.
17 SET @PageLowerBound=@PageIndex * @PageSize
18 SET @PageUpperBound=@PageLowerBound+@PageSize-1
19
20--创建临时表:
21--IndexId是标识,自动增长1;
22--SimpleId由数据表[Simple]填充;
23 CREATE TABLE #PageIndexForSimple
24 (
25 IndexId int identity(0,1) NOT NULL,
26 SimpleId int
27 )
28--填充临时表
29 INSERT INTO #PageIndexForSimple(SimpleId)
30 SELECT s.[SimpleId]
31 FROM [Simple] s
32 --这里可以加WHERE condition和ODER BY语句
33
34 --取得记录总数,其实影响行数就是记录总数
35 SELECT @TotalRecords=@@ROWCOUNT
36
37 --获取我们所要的记录.
38 SELECT s.*
39 FROM [Simple] s,#PageIndexForSimple p
40 WHERE s.[SimpleId]=p.[SimpleId]
41 AND p.[IndexId]>=@PageLowerBound
42 AND P.[IndexId]<=@PageUpperBound
43 ORDER BY s.[Simple]
44
45 --返回记录总数.
46 RETURE @TotalRecords
47END 由上面的注释就能看懂了,呵呵,既然写到这里也把程序的代码写出来:
1Public List GetSimple(int pageIndex,int pageIndex,out int totalRecords){
2 List entity=new List();
3 SqlParameter[]param=new SqlParameter[]{
4 new SqlParameter("@PageIndex",SqlDbType.Int),
5 new SqlParameter("@PageSize",SqlDbType.Int),
6 new SqlParameter("@ReturnValue",SqlDbType.Int),
7 };
8 param[0].Value=pageIndex;
9 param[1].Value=pageSize;
10 param[2].Direction = ParameterDirection.ReturnValue;
11 SqlDataReader reader=SqlHelper.ExecuteReader(CommandType.StoredProcedure, "GetSimple", param);
12 While(reader.Read()){
13 entity.Add(GetSimpleEntity(reader))
14 }
15 reader.Close();
16 try{
17 totalRecords=(int)param[2].Value;
18 }catch{}
19 return entity;
20} 上面的一些函数是自己写的:
SqlHelper类:简化数据库查询类.
GetSimpleEntity(SqlDataReader reader):由于经常在项目中会用到好基础实体类的获取,所以单独写一个私有函数,以便重用;
值得注意的是获取总的记录数时可能类型为DbNull而导致错误.




添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.