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。

评论

请稍候...
很抱歉,您输入的评论太长。请缩短您的评论。
您没有输入任何内容,请重试。
很抱歉,我们当前无法添加您的评论。请稍后重试。
若要添加评论,需要您的家长授予您相应权限。请求权限
您的家长禁用了评论功能。
很抱歉,我们当前无法删除您的评论。请稍后重试。
您已超过了一天之内允许提供的评论数上限。请在 24 小时后重试。
因为我们的系统表明您可能在向其他用户提供垃圾评论,您的帐户已禁用了评论功能。如果您认为我们错误地禁用了您的帐户,请联系 Windows Live 支持部门
完成下面的安全检查,您提供评论的过程才能完成。
您在安全检查中键入的字符必须与图片或音频中的字符一致。

若要添加评论,请使用您的 Windows Live ID 登录(如果您使用过 Hotmail、Messenger 或 Xbox LIVE,您就拥有 Windows Live ID)。登录


还没有 Windows Live ID 吗?请注册

引用通告

此日志的引用通告 URL 是:
http://microanty.spaces.live.com/blog/cns!4529DF58DA9D2E9C!1047.trak
引用此项的网络日志