当前位置: 首页 > 图文教程 > 网络编程 > ASP > 实现分页的例子-使用存储过程来实现分页

ASP
关于释放session的两篇文章(一)
关于释放session的两篇文章(二)
表单填写时用回车代替TAB的实现方式
DateDiff的用法
加快DHTML的一组技巧
全面考察“禁用浏览器后退按钮”
XML加ASP实现网页“本地化”
透过ASP修改NT使用者的密码
方便购买的电子商务站点设计技巧
使用ASPMail组件发送数字卡片
聊天室关键技术[用户断线]处理
生成类似Windows资源管理器
如何将代码生成的文件设为只读
ASP中巧用存储过程
拦截表单的另外一种写法
ASP实现OICQ式的信息收发功能
怎样用HtmlEncode显示Unicode?
ASP出错集成处理
ASP.NET中处理datetime的一些通用函数
ASP.NET实现HTTP方式获取功能

ASP 中的 实现分页的例子-使用存储过程来实现分页


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 20 ::
收藏到网摘: n/a

  在  网上 讨论 如何 实现 分页  有很多程序,我在这里向大家  介绍一种实现分页的新的方法,使用 存储过程 来实现分页
   由于 这段程序写的 比较早,那个时候 还没有 SQL 7,每一个 Varchar 只能 支持 255 个字符,所以 采取了一种比较笨的办法,如果大家有兴趣,请去  http://www.chinaasp.com/sqlbbs/default.asp 的数据库论坛发表意见,我会看情况,决定是否将这个 存储过程修改成为SQL 7 的存储过程;
   并在此起到 一个 抛砖引玉  的 作用
   这个 程序只能  达到  10 个 分页
if exists (select * from sysobjects where id = object_id('dbo.sp_productPage') and sysstat & 0xf = 4)
    drop procedure dbo.sp_productPage
GO

CREATE PROCEDURE sp_productPage
@intStart TINYINT=1,
@intEnd TINYINT=10
with ENCRYPTION
AS
  Declare @strProductID VARCHAR(8),@strProductName VARCHAR(20),
  @strSQL1 VARCHAR(100),
  @strSQL2 VARCHAR(100),
  @strSQL3 VARCHAR(100),
  @strSQL4 VARCHAR(100),
  @strSQL5 VARCHAR(100),
  @strSQL6 VARCHAR(100),
  @strSQL7 VARCHAR(100),
  @strSQL8 VARCHAR(100),
  @strSQL9 VARCHAR(100),
  @strSQL10 VARCHAR(100),
  @intCCount TINYINT,
  @intCount TINYINT,
  @i TINYINT
  select @i=1
  Declare cur_Product SCROLL CURSOR For
   Select ProductID,ProductName from KF_Product order by ProductID
   Select @intCCount=count(productId) From KF_Product
  open cur_Product
  Fetch ABSOLUTE @intStart From cur_Product Into @strProductID,@strProductName
  if @@FETCH_STATUS=0
    Select @intCount=@intStart
  Fetch cur_Product Into @strProductID,@strProductName
  if @@FETCH_STATUS=0
       Begin
         Select @intCount=@intCount+1
         Select @strSQL1='Select productId=''' + @strProductID + ''',productName=''' + @strProductName+ ''',ProductCount=' + convert(VARCHAR,@intCount)+',ProductSumCount='+ convert(VARCHAR,@intCCount) +' Union '
       End
   else
    Begin
       Select @strSQL1='Select productId=''' + @strProductID + ''',productName=''' + @strProductName+ ''',ProductCount=' + convert(VARCHAR,@intcCount)+',ProductSumCount='+ convert(VARCHAR,@intCCount)
       Goto EndPro
    End
  Fetch cur_Product Into @strProductID,@strProductName
  if @@FETCH_STATUS=0
       Begin
         Select @intCount=@intCount+1
         Select @strSQL2='Select productId=''' + @strProductID + ''',productName=''' + @strProductName+ ''',ProductCount=' + convert(VARCHAR,@intCount)+',ProductSumCount='+ convert(VARCHAR,@intCCount)+' Union '
       End
    else
       Begin
          Select @strSQL2='Select productId=''' + @strProductID + ''',productName=''' + @strProductName+ ''',ProductCount=' + convert(VARCHAR,@intcCount)+',ProductSumCount='+ convert(VARCHAR,@intCCount)
          Goto EndPro
       End
    Fetch cur_Product Into @strProductID,@strProductName
    if @@FETCH_STATUS=0
       Begin
         Select @intCount=@intCount+1
 &nb'