您的位置:首页 >> 编程开发 >> .NET >> 其它 >> 正文
RSS
 

[原创]存储过程DataGrid分页及注意点

http://www.rdxx.com 05年02月05日 12:12 Blog 我要投稿

关键词: 注意 , 分页 , 存储过程 , DataGrid , 存储

sqlserver中的存储过程完整代码
/*****************************************************************
* 存储过程名: GetCustomersDataPage 
* 过程描述: 通用大数据集分页
* 传入参数: 
* 传出参数: 
* 修改记录
* 姓名   日期   修改类型
* NickLee       2005-1-17     新建 
*
*
*
*
*
******************************************************************/
-- 获取指定页的数据

CREATE  PROCEDURE [GetCustomersDataPage]
         @PageIndex INT,                             --页面索引,从datagrid中获取
         @PageSize  INT,                              --页面显示数量,从datagrid中获取
         @RecordCount INT OUT,                --返回记录总数
         @PageCount INT OUT,                   --返回分页后页数
         @strGetFields nvarchar(1000),         -- 需要查询的列
         @tableName nvarchar(500) ,           --表名称
         @ID nvarchar(100),                          --主键,(为表的主键)
         @strWhere  nvarchar(1000) ='',        -- 查询条件 (注意: 不要加 where)
         @sortName nvarchar(50) =' asc ' ,     --排序方式
         @orderName nvarchar(100)              --父级查询排序方式

AS
declare @countSelect nvarchar(2000) 
--设置统计查询语句
if len(@strWhere) =0
--如果没有查询条件
    begin
        set @countSelect=N'SELECT @CountRecord = COUNT(*)  FROM '+@tableName
    end
else
--否则
    begin
        set @countSelect=N'SELECT @CountRecord = COUNT(*)  FROM '+@tableName+' where '+@strWhere
    end
--执行并返回总数
exec sp_executesql @countSelect,N'@CountRecord int output',@RecordCount output
SET @PageCount = CEILING(@RecordCount * 1.0 / @PageSize)

SET NOCOUNT ON

共5页  1 2 3 4 5

 
 
标签: 注意 , 分页 , 存储过程 , DataGrid , 存储 打印本文
 
 
  热点搜索
 
 
 



Valid XHTML 1.0 Transitional
Copyright ©2005 - 2008 Rdxx.Com,All Rights Reserved
收藏本页
收藏本站