·您的位置: 首页 » 资源教程 » 编程开发 » ASP » 实验RECORDSET.MOVENEXT,RECORDSET.PREVIOUS,RECORSET...等移动记录

实验RECORDSET.MOVENEXT,RECORDSET.PREVIOUS,RECORSET...等移动记录

类别: ASP教程  评论数:0 总得分:0
我在实验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>
-= 资 源 教 程 =-
文 章 搜 索
关键词:
类型:
范围:
纯粹空间 softpure.com
Copyright © 2006-2008 暖阳制作 版权所有
QQ: 15242663 (拒绝闲聊)  Email: faisun@sina.com
 纯粹空间 - 韩国酷站|酷站欣赏|教程大全|资源下载|免费博客|美女壁纸|设计素材|技术论坛   Valid XHTML 1.0 Transitional
百度搜索 谷歌搜索 Alexa搜索 | 粤ICP备19116064号-1