| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 4657 人关注过本帖
标题:do while与for循环的区别
取消只看楼主 加入收藏
ab382717036
Rank: 2
等 级:论坛游民
帖 子:73
专家分:20
注 册:2011-3-19
结帖率:91.67%
收藏
已结贴  问题点数:10 回复次数:7 
do while与for循环的区别
这里我用for循环页面就出现
错误类型:
ADODB.Field (0x80020009)
BOF 或 EOF 中有一个是“真”,或者当前的记录已被删除,所需的操作要求一个当前的记录。
/人才招聘系统asp.0602/page.asp
而用Do while 循环就能实现分页功能
<!--#include file="Conn.asp" -->
<!--#include file="Comm/Site_Class.asp" -->
<%
PagePath = ""

Set Qsite = New Site_Class

Qsite.SiteConfig_Master()
%>
<%
Dim Rs,Sql,i,CurrentPage,FileName,j
Dim PersonName,ViewType
Dim PerId
Dim Act,IsHidden,IsLock,IsGj,IsTj,IsYear,IsSh
Dim TodayDate
Set Rs = server.CreateObject("ADODB.recordset")

%>
<html xmlns="http://www.
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>简历管理</title>
<link href="../skins/css/main.css" rel="stylesheet" type="text/css">


<body>
<table width="100%" border="0" cellspacing="1" cellpadding="5">
    <tr>
        <td width="8%" class="td_content"><strong>用户名</strong></td>
        <td width="8%" class="td_content"><strong>真实姓名</strong></td>
        <td width="6%" class="td_content"><strong>性别</strong></td>
        <td width="6%" class="td_content"><strong>年龄</strong></td>
        <td width="8%" class="td_content"><strong>学历</strong></td>
        <td width="12%" class="td_content"><strong>求职意向</strong></td>
    </tr>
<%
Rs.Open "select * from PersonTbl order by EditDate desc", Conn , 1 , 1
If Rs.Eof Then
%>
    <tr>
        <td height="45" colspan="11" class="td_content">暂无简历信息</td>
    </tr>
<%
Else
    CurrentPage=Clng(Request("page"))
    Rs.PageSize=15
    if CurrentPage="" Then CurrentPage=1
    if isNumeric(CurrentPage) Then CurrentPage=int(CurrentPage)
    if CurrentPage<1 Then CurrentPage=1
    if CurrentPage>rs.pagecount  Then
       CurrentPage=rs.pagecount
     End if
     if CurrentPage<=rs.pagecount and rs.pagecount>0 Then
     rs.absolutepage=CurrentPage
     End if
    i = 0
    if not rs.Eof Then  ------------
     for j=1 to rs.recordcount-----------改为DO While not rs.Eof
%>
    <tr>
        <td class="td_content"><%=Rs("UserName")%></td>
        <td class="td_content"><%=Rs("RealName")%></a></td>
        <td class="td_content"><%=Rs("Sex")%></td>
        <td class="td_content"><%=Rs("Age")%></td>
        <td class="td_content"><%=Rs("Qualification")%></td>
        <td class="td_content"><%=Rs("JobPost")%></td>
<%
    i = i + 1
    response.Write(i)
    response.Write(j)
    response.Write("<br>")
    Rs.MoveNext
    If i >= Rs.PageSize Then Exit For-------For 改为Do
    next------------------------------------Loop
End if
End If
%>
</table>
<%If Rs.pagecount>1 Then%>
<% If CurrentPage > 1 Then %>
<a href="page.asp?page=<%=CurrentPage-1%>">前一页</a>&nbsp;
  <% Else %>
  首页 上页
  <% End if%>
  <%  If CurrentPage < Rs.pagecount Then %>
<a href="page.asp?page=<%=CurrentPage+1%>">后一页</a>&nbsp;
<% End if%>
<a href="page.asp?page=<%=rs.pagecount%>">末页</a>
<% End if%>
</p>
<p align="center">现在是第<%=CurrentPage%>页一共有<%=rs.pagecount%>页</p>
<%
Rs.Close
%>

</body>
</html>
搜索更多相关主题的帖子: 人才招聘 
2011-03-30 15:14
ab382717036
Rank: 2
等 级:论坛游民
帖 子:73
专家分:20
注 册:2011-3-19
收藏
得分:0 
我只想知道我那种情况 for循环为什么不行,而Do while 循环可以
2011-03-30 15:56
ab382717036
Rank: 2
等 级:论坛游民
帖 子:73
专家分:20
注 册:2011-3-19
收藏
得分:0 
<!--#include file="Conn.asp" -->
<!--#include file="Comm/Site_Class.asp" -->
<%
PagePath = ""

Set Qsite = New Site_Class

Qsite.SiteConfig_Master()
%>
<%
Dim Rs,Sql,i,CurrentPage,FileName,j
Dim PersonName,ViewType
Dim PerId
Dim Act,IsHidden,IsLock,IsGj,IsTj,IsYear,IsSh
Dim TodayDate
Set Rs = server.CreateObject("ADODB.recordset")

%>
<html xmlns="http://www.
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>简历管理</title>
<link href="../skins/css/main.css" rel="stylesheet" type="text/css">


<body>
<table width="100%" border="0" cellspacing="1" cellpadding="5">
    <tr>
        <td width="8%" class="td_content"><strong>用户名</strong></td>
        <td width="8%" class="td_content"><strong>真实姓名</strong></td>
        <td width="6%" class="td_content"><strong>性别</strong></td>
        <td width="6%" class="td_content"><strong>年龄</strong></td>
        <td width="8%" class="td_content"><strong>学历</strong></td>
        <td width="12%" class="td_content"><strong>求职意向</strong></td>
    </tr>
<%
Rs.Open "select * from PersonTbl order by EditDate desc", Conn , 1 , 1
If Rs.Eof Then
%>
    <tr>
        <td height="45" colspan="11" class="td_content">暂无简历信息</td>
    </tr>
<%
Else
    CurrentPage=Clng(Request("page"))
    Rs.PageSize=15
    if CurrentPage="" Then CurrentPage=1
    if isNumeric(CurrentPage) Then CurrentPage=int(CurrentPage)
    if CurrentPage<1 Then CurrentPage=1
    if CurrentPage>rs.pagecount  Then
       CurrentPage=rs.pagecount
     End if
     if CurrentPage<=rs.pagecount and rs.pagecount>0 Then
     rs.absolutepage=CurrentPage
     End if
    i = 0
     for j=1 to rs.recordcount
%>
    <tr>
        <td class="td_content"><%=Rs("UserName")%></td>
        <td class="td_content"><%=Rs("RealName")%></a></td>
        <td class="td_content"><%=Rs("Sex")%></td>
        <td class="td_content"><%=Rs("Age")%></td>
        <td class="td_content"><%=Rs("Qualification")%></td>
        <td class="td_content"><%=Rs("JobPost")%></td>
<%
    i = i + 1
    response.Write(i)
    response.Write(j)
    response.Write("<br>")
    Rs.MoveNext
    If i >= Rs.PageSize Then Exit For-------If rs.eof then exit for改为这句为什么又可以了
    next
End if
End If
%>
</table>
<%If Rs.pagecount>1 Then%>
<% If CurrentPage > 1 Then %>
<a href="page.asp?page=<%=CurrentPage-1%>">前一页</a>&nbsp;
  <% Else %>
  首页 上页
  <% End if%>
  <%  If CurrentPage < Rs.pagecount Then %>
<a href="page.asp?page=<%=CurrentPage+1%>">后一页</a>&nbsp;
<% End if%>
<a href="page.asp?page=<%=rs.pagecount%>">末页</a>
<% End if%>
</p>
<p align="center">现在是第<%=CurrentPage%>页一共有<%=rs.pagecount%>页</p>
<%
Rs.Close
%>

</body>
</html>
2011-03-31 08:53
ab382717036
Rank: 2
等 级:论坛游民
帖 子:73
专家分:20
注 册:2011-3-19
收藏
得分:0 
计数器的条数难道不等于数据读完时的条数吗
2011-03-31 15:10
ab382717036
Rank: 2
等 级:论坛游民
帖 子:73
专家分:20
注 册:2011-3-19
收藏
得分:0 
我算了一下  i和j输出的结果是一样的
2011-03-31 18:37
ab382717036
Rank: 2
等 级:论坛游民
帖 子:73
专家分:20
注 册:2011-3-19
收藏
得分:0 
<!--#include file="Conn.asp" -->
<!--#include file="Conn1.asp"-->
<!--#include file="Comm/Site_Class.asp" -->
<%
PagePath = ""

Set Qsite = New Site_Class

Qsite.SiteConfig_Master()
Dim Rs,Sql,CurrentPage,FileName,Sql1,Rs1
Dim PersonName,ViewType
Dim PerId
Dim Act,IsHidden,IsLock,IsGj,IsTj,IsYear,IsSh
Dim TodayDate
Dim j,s,m,n,i,x
Dim A(),B(),C()
m=0
n=0
x=0
   Set rs=server.CreateObject("ADODB.Recordset")
   '打开记录集对象
%>
<title>网站公告页面</title>
</head>

<BODY>


<table width="100%" border="0" cellspacing="1" cellpadding="5">
    <tr>
        <td width="8%" class="td_content"><strong>用户名</strong></td>
        <td width="8%" class="td_content"><strong>真实姓名</strong></td>
        <td width="6%" class="td_content"><strong>性别</strong></td>
        <td width="6%" class="td_content"><strong>年龄</strong></td>
        <td width="8%" class="td_content"><strong>学历</strong></td>
        <td width="12%" class="td_content"><strong>求职意向</strong></td>
    </tr>

<%
   Set Rs1=server.CreateObject("ADODB.Recordset")
   Rs1.open "Select * from UserTB",Conn1,1,1
     If Not Rs1.Eof Then
          for j=1 to rs1.recordcount
          ReDim Preserve B(2,rs1.recordcount)
          B(1,j)=Rs1("PerId")
          B(2,j)=Rs1("FUname")
          m=m+1
          rs1.movenext
          next
          End if
     Rs1.close
  Set Rs=server.CreateObject("ADODB.Recordset")
  Rs.open "select * from test",Conn,1,1
  if Not Rs.Eof Then
   for j=1 to Rs.Recordcount
   ReDim Preserve A(2,rs.recordcount)
     A(1,j)=Rs("PerId")
     A(2,j)=Rs("UserName")
     n=n+1
     rs.movenext
     next
     End if
     Rs.close
     s=m+n
     
     
     for i=1 to n
     ReDim preserve B(2,s)
     B(1,m+i)=A(1,i)
     B(2,m+i)=A(2,i)
     next
  Set Rs=server.CreateObject("ADODB.Recordset")
   Rs.open "Select * from PersonTbl order by EditDate desc",Conn,1,1
     If Not Rs.Eof Then
     for j=1 to rs.recordcount
     x=x+1
     ReDim Preserve C(7,rs.recordcount)
     C(2,j)=Rs("sex")
     C(3,j)=Rs("age")
     C(4,j)=Rs("realname")
     C(5,j)=Rs("Qualification")
     C(6,j)=Rs("JobPost")
     C(1,j)=Rs("PerId")
     C(7,j)=""
     rs.movenext
     next
     End if
     Rs.close
     for i=1 to x
       for j=1 to s
        if C(1,i)<>B(1,j) Then
        Else
        C(7,i)=B(2,j)
        End if
        next
     next
  '定义循环变量
 rs.open "select * from PersonTbl order by EditDate desc",Conn,1,1
   rs.pagesize=15
   '得到请求的页号
   CurrentPage=clng(request("page"))
   IF request("page")<>"" then
     CurrentPage=clng(request("page"))
   Else
     CurrentPage=1
   End IF
   IF CurrentPage<1 Then CurrentPage=1
   If CurrentPage>rs.pagecount Then CurrentPage=rs.pagecount
  rs.absolutepage=CurrentPage
  for  i=1 to rs.recordcount--------现在是这样的情况如果用循环 for i=1 to rs.recordcount 时 一个页面就显示完了rs.pagesize根本就没有控制住,
                                    如果用 for i=1 to rs.pagesize 数组C()在rs.pagesize就结束了,我想让数据库记录的数跟数组同时结束,怎么解决
  ReDim Preserve C(7,rs.recordcount)
  %>
  <tr>
        <td class="td_content"><%=C(7,i)%></td>
        <td class="td_content"><%=C(4,i)%>||<%=Rs("realname")%></td>
        <td class="td_content"><%=C(2,i)%>||<%=Rs("sex")%></td>
        <td class="td_content"><%=C(3,i)%>||<%=Rs("age")%></td>
        <td class="td_content"><%=C(5,i)%>||<%=Rs("Qualification")%></td>
        <td class="td_content"><%=C(6,i)%>||<%=Rs("JobPost")%></td>
</tr>
  <%
   rs.MoveNext
   IF rs.Eof Then Exit For
  next
  %>
</table>
<table width="400" border="0">
  <tr>
  <%
  '翻页控制代码
  IF CurrentPage<>1 Then
    Response.Write("<td><a href=aa.asp?page=1>第一页</a></td>")
    Response.Write("<td><a href=aa.asp?page="&(CurrentPage-1)&">上一页</a></td>")
  Else
    Response.Write("<td>第一页</td>")
    Response.Write("<td>上一页</td>")
  End IF   
  IF CurrentPage<>rs.pagecount then
    Response.Write("<td><a href=aa.asp?page=" & (CurrentPage+1) & ">下一页</a></td>")
    Response.Write("<td><a href=aa.asp?page=" & rs.pagecount & ">最后一页</a></td>")
  Else
    Response.Write("<td>下一页</span></td>")
    Response.Write("<td>最后一页</span></td>")
  End IF
  %>
    <td>共<%=rs.pagecount%>页</td>
    <td>当前第<%=CurrentPage%>页</td>
  </tr>
</table>
<%
'网页对象析构代码
rs.Close
conn.Close
Set rs=Nothing
Set conn=Nothing
%>
</body>
</html>

运行后出现重复而且Rs.PageSize=15根本没控制住怎么回事
第一个页面就全部显示完了

路成军     路成军          25     本科     程序员
xiaoye2234     王小叶          23     大专     助理
richard77     傅振国          30     本科     外贸业务员
nancy2002     高琴琼          22     本科     翻译
manxin     王温丽          22     大专     外贸单证
王秧飞     王秧飞          25     高中及以下     金融
denisegong     龚琼盛          28     大专     其他
pursuit     梁飞杰          22     本科     外贸业务员
yi4218     曹麟义          27     大专     外贸跟单
zdy123     周道园          26     高中及以下     其它
monicazyj     张郁佳          25     大专     外贸采购或助理
第二个页面跟第一个页面重复
王秧飞     王秧飞          25     高中及以下     金融
denisegong     龚琼盛          28     大专     其他
pursuit     梁飞杰          22     本科     外贸业务员
yi4218     曹麟义          27     大专     外贸跟单
zdy123     周道园          26     高中及以下     其它
monicazyj     张郁佳          25     大专     外贸采购或助理


[ 本帖最后由 ab382717036 于 2011-4-2 15:54 编辑 ]
2011-04-02 14:07
ab382717036
Rank: 2
等 级:论坛游民
帖 子:73
专家分:20
注 册:2011-3-19
收藏
得分:0 
求助 求助
2011-04-02 15:55
ab382717036
Rank: 2
等 级:论坛游民
帖 子:73
专家分:20
注 册:2011-3-19
收藏
得分:0 
  自己终于把问题解决了不容易啊
2011-04-02 17:08
快速回复:do while与for循环的区别
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.027345 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved