论坛交流
首页办公自动化| 网页制作| 平面设计| 动画制作| 数据库开发| 程序设计| 全部视频教程
应用视频: Windows | Word2007 | Excel2007 | PowerPoint2007 | Dreamweaver 8 | Fireworks 8 | Flash 8 | Photoshop cs | CorelDraw 12
编程视频: C语言视频教程 | HTML | Div+Css布局 | Javascript | Access数据库 | Asp | Sql Server数据库Asp.net  | Flash AS
当前位置 > 文字教程 > asp教程
Tag:入门,文摘,实例,技巧,iis,表单,对象,上传,数据库,记录集,session,cookies,存储过程,注入,分页,安全,优化,xmlhttp,fso,jmail,application,防盗链,stream,组件,md5,乱码,缓存,加密,验证码,算法,ubb,正则表达式,水印,,日志,压缩,url重写,控件,函数,破解,触发器,socket,ADO,初学,聊天室,留言本,视频教程

实验Recordset.Movenext,Recordset.Previous,Recorset...等移动记录

文章类别:asp | 发表日期:2008-10-5 20:55:39

我在实验Recordset.Movenext,Recordset.Previous,Recorset.......等移动记录的时候遇到了困难.
我用Access做后台数据库,通过一个查询条件查询得一个记录集,我想用一个表格实现记录的逐条浏览(不是一组记录分页浏览). 即"共查到**条记录,现在是第*条",单击"Next"按钮后下一条记录的内容显示在表格中.....

我用如下代码实现(见最后)

发现若将Rst.Open "select * from 某表 where 从某个Form获取的查询条件"
改成  Rst.Open "select * from 某表"(相当于不做查询动作)后, 记录的浏览功能才得以实现.
否则总是出现" EOF或BOF为真 "的错误提示.可我明明可以从"某表"中 "select... where..."到好几个记录的!

总之如何将"记录的逐条浏览"和"select * from 某表 where 从某个Form获取的查询条件" 结合起来?

望予以指点为感!

杨利
2000/4/13

程序代码:

<%@ LANGUAGE=VBScript %>
<!-- #Include file="ADOVBS.INC" -->
<html>
<head>
<title></title>
</head>
<body BGCOLOR="#FFFFF0">
<h3 align="center"><font face="隶书" color="#004080"><big>现在您可以编辑以下记录</big></font></h3>
<!-- 在服务器上创建 Connection 和 Recordset 对象 -->
<%
'创建并打开 Connection 对象。
Set cn=Server.CreateObject("ADODB.Connection")
    cn.Open "DSN=数据库名"
'创建并打开 Recordset 对象。
Set Rst = Server.CreateObject("ADODB.Recordset")
    Rst.ActiveConnection = cn
    Rst.CursorType = adOpenKeyset
    Rst.LockType = adLockOptimistic   
Rst.Open "select * from 某表 where 性别='"&request.form("t1")&"'"(执行这句大有问题)
Rst.Open "select * from 某表 where 性别='男'"(执行这句有点问题)
Rst.Open "select * from hr_base"(执行这句没有问题)
' 检查 Request.Form 集合以查看所记录的任何移动。
If Not IsEmpty(Request.Form("MoveAmount")) Then
' 跟踪该会话的移动数目和方向。
   Session("Moves") = Session("Moves") + Request.Form("MoveAmount")
   Clicks = Session("Moves")
'移动到上一个已知位置。
   Rst.Move CInt(Clicks)
'检查移动为 + 还是 - 并进行错误检查。
      If CInt(Request.Form("MoveAmount")) = 1 Then
         If Rst.EOF Then
            Session("Moves") = Rst.RecordCount
            Rst.MoveLast
         End If   
         Rst.MoveNext
      End If
      If Request.Form("MoveAmount") < 1 Then
         Rst.MovePrevious
      End If
'检查有无单击 First Record 或 Last Record 命令按钮。
      If Request.Form("MoveLast") = 3 Then
         Rst.MoveLast
         Session("Moves") = Rst.RecordCount
      End If
      If Request.Form("MoveFirst") = 2 Then
         Rst.MoveFirst
         Session("Moves") = 1
      End If
End If
' 对 Move Button 单击组合进行错误检查。
      If Rst.EOF Then
         Session("Moves") = Rst.RecordCount
         Rst.MoveLast
         Response.Write "This is the Last Record"
         End If   
         If Rst.BOF Then
         Session("Moves") = 1
         Rst.MoveFirst
         Response.Write "This is the First Record"
      End If
   %>
<!-- 显示当前记录数目和记录集大小-->
<h3 align="center"><font face="隶书" color="#004080">共查到</font><font color="#600060"><%=Rst.RecordCount%></font><font face="隶书" color="#004080">条记录,当前为第</font>
<font color="#600060">
<%
If IsEmpty(Session("Moves"))  Then
           Session("Moves") =1
End If
%>
<%Response.Write(Session("Moves") )%>
</font><font face="隶书" color="#004080">条记录</font></h3>
<hr align="center">
<p align="center">  <input Type="button" Name="cmdFirst" Value="第一条"                                     
style="font-family: 宋体"><input Type="button" Name="cmdDown" Value="上一条"><input                                     
Type="button" Name="cmdUp" Value="下一条"><input Type="button" Name="cmdLast"                                     
Value="末一条"> </p>                                                                     
<p align="center"><b><font size="5" color="#000080" face="隶书">查询结果:</font></b></p>                                        
                                        
<table>
(用于逐条显示记录的表格)                                       
</table>   
                                    
<!-- 使用隐含窗体字段将值发送到服务器-->                                                                       
<form Method="Post" Action Name="Form">                                    
  <input type="hidden" name="MoveAmount" value="0"><input type="hidden" name="MoveLast"                                    
  value="0"><input type="hidden" name="MoveFirst" value="0">                                    
</form>                                    
</body>                                    
<script Language="VBScript">                                                                        
Sub cmdDown_OnClick                                    
'在 Input Boxes 窗体和 Submit 窗体中设置值。                                                                 
   Document.Form.MoveAmount.Value = -1                                    
   Document.Form.Submit                                    
End Sub                                                                       
Sub cmdUp_OnClick                                                                        
   Document.Form.MoveAmount.Value = 1                                    
   Document.Form.Submit                                    
End Sub                                                                        
Sub cmdFirst_OnClick                                                                       
   Document.Form.MoveFirst.Value = 2   Document.Form.Submit                                      
End Sub                                                                        
Sub cmdLast_OnClick                                                                        
   Document.Form.MoveLast.Value =3                                    
   Document.Form.Submit                                    
End Sub                                    
</script>                                                            
</html> 
视频教程列表
文章教程搜索
 
Asp推荐教程
Asp热门教程
看全部视频教程
购买方式/价格
购买视频教程: 咨询客服
tel:15972130058