注册 登录
编程论坛 ASP技术论坛

当前的记录已被删除,所需的操作要求一个当前的记录.[感谢yms123老师,在您指点下已解决!]

tepnidh 发布于 2012-02-12 12:12, 539 次点击

问题描述:做网站后台管理,有" 添加","修改","删除"3个页面,当数据库中的数据表无记录时,3个页面都无法访问,提示:
"错误类型:
ADODB.Field (0x80020009)
BOF 或 EOF 中有一个是“真”,或者当前的记录已被删除,所需的操作要求一个当前的记录。"

这样,搞得我在"添加"页面无法再次输入新的数据,只好把数据库打开,在数据表中重新输入.我想请教大家的是:当记录集查询到数据表中无数据时,能否使后台编辑页面显示,点击"添加"进入添加页面,同时,提示"暂时无数据"等类似的语句.多谢
附:后台图片编辑页面
<!--#include file="../conn.asp" -->
<%
Set rs = Server.CreateObject ("ADODB.Recordset")
sql = "Select * from lunbo  ORDER BY id DESC"
rs.Open sql,conn,1,1
%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
<style type="text/css">
<!--
.STYLE1 {
    font-size: 24px;
    color: #0066FF;
}
-->
</style>
</head>

<body>
<table width="780" border="1" cellspacing="0" cellpadding="0">

  <tr>
    <td width="630" height="40" align="center" bgcolor="#00FFFF"><span class="STYLE1">图 片 后 台 编 辑</span></td>
    <td colspan="3" align="center" bgcolor="#00FFFF"  ><a href="htj-lunb.asp?id=<% =rs("id")%>">添&nbsp; 加</a></td>
  </tr>
  <%
if rs.EOF and rs.BOF then
response.write
else
Do Until rs.EOF %>
  <tr>
  
    <td align="center"><img src="<%=rs("pic1")%>" width="100" height="70"> </td>
    <td align="center"><a href="hscgd-lunb.asp?id=<%=rs("id") %>">删&nbsp; 除</a></td>
    <td align="center"><a href="hxg-lunb.asp?id=<%=rs("id") %>">修&nbsp; 改</a></td>
  </tr>
  <% rs.MoveNext
Loop
end if
%>
</table>
</body>
</html>


[ 本帖最后由 tepnidh 于 2012-2-12 18:19 编辑 ]
2 回复
#2
yms1232012-02-12 16:11
你在显示时对bof或eof判断一下即可
<!--#include file="../conn.asp" -->
<%
Set rs = Server.CreateObject ("ADODB.Recordset")
sql = "Select * from lunbo  ORDER BY id DESC"
rs.Open sql,conn,1,1
%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
<style type="text/css">
<!--
.STYLE1 {
    font-size: 24px;
    color: #0066FF;
}
-->
</style>
</head>

<body>
<table width="780" border="1" cellspacing="0" cellpadding="0">

  <tr>
    <td width="630" height="40" align="center" bgcolor="#00FFFF"><span class="STYLE1">图 片 后 台 编 辑</span></td>
    <td colspan="3" align="center" bgcolor="#00FFFF"  >
     <%
        if not rs.eof then%>
           <a href="htj-lunb.asp?id=<% =rs("id")%>">添&nbsp; 加</a>
        <%else%>
           <a href="htj-lunb.asp">添&nbsp; 加</a>
     <% end if%>
    </td>
  </tr>
  <%
if rs.EOF and rs.BOF then
response.write
else
Do Until rs.EOF %>
  <tr>
  
    <td align="center"><img src="<%=rs("pic1")%>" width="100" height="70"> </td>
    <td align="center"><a href="hscgd-lunb.asp?id=<%=rs("id") %>">删&nbsp; 除</a></td>
    <td align="center"><a href="hxg-lunb.asp?id=<%=rs("id") %>">修&nbsp; 改</a></td>
  </tr>
  <% rs.MoveNext
Loop
end if
%>
</table>
</body>
</html>
#3
tepnidh2012-02-12 18:17
回复 2楼 yms123
谢谢您yms123老师!真是高手,不愧是版主啊!经测试,成功!再次感谢,以后还请老师多多指点!
送您50分以示谢意!(呵~~~~就这么多了)

[ 本帖最后由 tepnidh 于 2012-2-12 18:23 编辑 ]
1