ant 的个人资料microant照片日志列表更多 ![]() | 帮助 |
|
8月25日 gridview存储过程分页(一) 抽空写一下自己用的关于GridView存储过程分页的代码,优点就不用多说了,主要是用于数据库端分页,解决数据量过大的分页问题。存储过程还是以前写的CTE方法的分页,还是在这里贴一下代码吧,具体请见存储过程分页实现代码,2005 T-SQL新增功能一文。 USE [WGSMSDbase] GO /****** 对象: StoredProcedure [dbo].[sp_CTE] 脚本日期: 08/25/2007 11:39:01 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO![]() ![]() -- ============================================= -- Author: <Author,,microant> -- Create date: <Create Date,,20070705> -- Description: <Description,,CTE分页> -- ============================================= CREATE PROCEDURE [dbo].[sp_CTE]( -- Add the parameters for the stored procedure here @TableName nvarchar(200) = 'testTable', --表名 @PageSize int = 15, --页面大小 @PageIndex int =2 , --页面的序号 --@IsCountNull bit =1, --返回记录是否为空 @IsAsc bit = 1 , --是否卫升序,升序为1,降序为0 @OderColumName nvarchar(200) = null, --排序字段名 @KeyID nvarchar(50) = 'id', --主键 @Conditions nvarchar(500) = null --查询条件 ) AS![]() -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON;![]() declare @strSql nvarchar(1000) declare @tempstr nvarchar(1000) declare @orderstr nvarchar(400) declare @ctestr nvarchar(400) --判断排序方式,@IsAsc =1 升序, 0降序,设置排序语句 if @IsAsc = 1 begin if(@OderColumName is null or @OderColumName = '') set @orderstr = ' order by ' + @KeyID + ' asc' else set @orderstr = ' order by ' + @OderColumName + ' asc' end else begin if(@OderColumName is null or @OderColumName = '') set @orderstr = ' order by ' + @KeyID + ' desc' else set @orderstr = ' order by ' + @OderColumName + ' desc' end --CTE set @ctestr ='with Table_CET as ( select CEILING((ROW_NUMBER() OVER (' + @orderstr + '))/' + str(@PageSize) + ') as page_num, * from ' + @TableName + ')' ; begin if(@Conditions is null or @Conditions = '') set @strSql = @ctestr + 'select * from Table_CET where page_num = ' + str(@PageIndex); else set @strSql = @ctestr + 'select * from Table_CET where page_num = ' + str(@PageIndex)+ ' and ' + @Conditions; print @strSql end begin exec sp_executesql @strSql end![]() ![]() ![]() 客户端代码如下,主要包含首页,末页,上一页,下一页,当前页码,总页码等一些必要信息,最主要的就是给按钮添加处理事件OnClick。 引用通告此日志的引用通告 URL 是: http://microanty.spaces.live.com/blog/cns!4529DF58DA9D2E9C!1047.trak 引用此项的网络日志
|
|
|