首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > ASP >

如果没有记录,怎么处理

2013-04-07 
如果没有记录,怎么办?%Dim Recordset_ZhaGong_PiZhuenDim Recordset_ZhaGong_PiZhuen_cmdDim Recordset_Z

如果没有记录,怎么办?
<%
Dim Recordset_ZhaGong_PiZhuen
Dim Recordset_ZhaGong_PiZhuen_cmd
Dim Recordset_ZhaGong_PiZhuen_numRows

Set Recordset_ZhaGong_PiZhuen_cmd = Server.CreateObject ("ADODB.Command")
Recordset_ZhaGong_PiZhuen_cmd.ActiveConnection = MM_TianShen_STRING
Recordset_ZhaGong_PiZhuen_cmd.CommandText = "select * FROM ZhaGongGongShi WHERE  id1 is not null " 
Recordset_ZhaGong_PiZhuen_cmd.Prepared = true
Set Recordset_ZhaGong_PiZhuen = Recordset_ZhaGong_PiZhuen_cmd.Execute
Recordset_ZhaGong_PiZhuen_numRows = 0
%>

上述SQL命令,如果记录行数>=1,则ASP页面,正常浏览.

上述SQL命令,如果记录行数=0,则ASP页面,则提示出错.



当运行到如下命令时:   <td><%=(Recordset_ZhaGong_PiZhuen.Fields.Item
("danjuhao").Value)%></td>

出错信息为:

ADODB.Field 错误 '800a0bcd' 
BOF 或 EOF 中有一个是“真”,或者当前的记录已被删除,所需的操作要求一个当前的记录。


问一下:如果遇到没有记录的情况,应该怎么处理呢?

由于是初学,望各位老师,指点的时候,详尽些.

在此,先谢了.






[解决办法]
判断是否有记录不就行了。

<%
Dim Recordset_ZhaGong_PiZhuen
Dim Recordset_ZhaGong_PiZhuen_cmd
Dim Recordset_ZhaGong_PiZhuen_numRows

Set Recordset_ZhaGong_PiZhuen_cmd = Server.CreateObject ("ADODB.Command")
Recordset_ZhaGong_PiZhuen_cmd.ActiveConnection = MM_TianShen_STRING
Recordset_ZhaGong_PiZhuen_cmd.CommandText = "select * FROM ZhaGongGongShi WHERE  id1 is not null " 
Recordset_ZhaGong_PiZhuen_cmd.Prepared = true
Set Recordset_ZhaGong_PiZhuen = Recordset_ZhaGong_PiZhuen_cmd.Execute
Recordset_ZhaGong_PiZhuen_numRows = 0

if Recordset_ZhaGong_PiZhuen.eof or Recordset_ZhaGong_PiZhuen.bof then
  response.write "没有记录"
else
'....读数据。。
%>
<td><%=(Recordset_ZhaGong_PiZhuen.Fields.Item
("danjuhao").Value)%></td>
<%

end if
%>

热点排行