中国IT动力,最新最全的IT技术教程
最新100篇 | 推荐100篇 | 专题100篇 | 排行榜 | 搜索 | 在线API文档
首 页 | 程序开发 | 操作系统 | 软件应用 | 图形图象 | 网络应用 | 精文荟萃 | 教育认证 | 硬件维护 | 未整理篇 | 站长教程
ASP JS PHP工程 ASP.NET 网站建设 UML J2EESUN .NET VC VB VFP 网络维护 数据库 DB2 SQL2000 Oracle Mysql
服务器 Win2000 Office C DreamWeaver FireWorks Flash PhotoShop 上网宝典 CorelDraw 协议大全 网络安全 微软认证
硬件维护  CPU  主板  硬盘  内存  显卡  显示器  键盘鼠标  声卡音箱  打印机  机箱电源  BIOS  网卡  C#  Java  Delphi  vs.net2005
  当前位置:> 程序开发 > Web开发 > Asp > 综合文章
实现分页的例子-使用存储过程来实现分页
作者:佚名 时间:2004-10-05 10:44 出处:互连网 责编:chinaitpower
              摘要:实现分页的例子-使用存储过程来实现分页
在  网上 讨论 如何 实现 分页  有很多程序,我在这里向大家  介绍一种实现分页的新的方法,使用 存储过程 来实现分页
   由于 这段程序写的 比较早,那个时候 还没有 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
         Select @strSQL3='Select productId='' + @strProductID + '',productName='' + @strProductName+ '',ProductCount=' + convert(VARCHAR,@intCount)+',ProductSumCount='+ convert(VARCHAR,@intCCount)+' Union '
       End
    else
      Begin
       Select @strSQL3='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 @strSQL4='Select productId='' + @strProductID + '',productName='' + @strProductName+ '',ProductCount=' + convert(VARCHAR,@intCount)+',ProductSumCount='+ convert(VARCHAR,@intCCount)+' Union '
       End
    else
      Begin
       Select @strSQL4='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 @strSQL5='Select productId='' + @strProductID + '',productName='' + @strProductName+ '',ProductCount=' + convert(VARCHAR,@intCount)+',ProductSumCount='+ convert(VARCHAR,@intCCount)+' Union '
       End
    else
      Begin
       Select @strSQL5='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 @strSQL6='Select productId='' + @strProductID + '',productName='' + @strProductName+ '',ProductCount=' + convert(VARCHAR,@intCount)+',ProductSumCount='+ convert(VARCHAR,@intCCount)+' Union '
       End
    else
      Begin
       Select @strSQL6='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 @strSQL7='Select productId='' + @strProductID + '',productName='' + @strProductName+ '',ProductCount=' + convert(VARCHAR,@intCount)+',ProductSumCount='+ convert(VARCHAR,@intCCount)+' Union '
       End
    else
      Begin
       Select @strSQL7='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 @strSQL8='Select productId='' + @strProductID + '',productName='' + @strProductName+ '',ProductCount=' + convert(VARCHAR,@intCount)+',ProductSumCount='+ convert(VARCHAR,@intCCount)+' Union '
       End
    else
      Begin
       Select @strSQL8='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 @strSQL9='Select productId='' + @strProductID + '',productName='' + @strProductName+ '',ProductCount=' + convert(VARCHAR,@intCount)+',ProductSumCount='+ convert(VARCHAR,@intCCount)+' Union '
       End
    else
      Begin
       Select @strSQL9='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 @strSQL10='Select productId='' + @strProductID + '',productName='' + @strProductName+ '',ProductCount=' + convert(VARCHAR,@intCount)+',ProductSumCount='+ convert(VARCHAR,@intCCount)
       End
    else
      Begin
       Select @strSQL10='Select productId='' + @strProductID + '',productName='' + @strProductName+ '',ProductCount=' + convert(VARCHAR,@intcCount)+',ProductSumCount='+ convert(VARCHAR,@intCCount)
       Goto EndPro
      End
EndPro:  
close cur_Product
DEALLOCATE  cur_Product
print @strSQL1
print @strSQL2
print @strSQL3
exec(@strSQL1 + @strSQL2+ @strSQL3+@strSQL4+@strSQL5+@strSQL6+@strSQL7+@strSQL8+@strSQL9+@strSQL10)
GO
存储 过程创建 成功后,就可以在ASP 中 做 如下 调用
strSQL="sp_productPage 1,10
rst.open strSQL,conn,3,1
就可以了


关闭本页
 
首页 | 投资与合作 | 服务条款 | 隐私政策 | 收藏本站 | 设为首页 | 新用户注册 | 免责声明 | 使用帮助
Copyright ©2005-2008 chinaitpower.com All rights reserved. www.chinaitpower.com 版权所有