asp图片显示

来源:百度知道 编辑:UC知道 时间:2024/06/16 15:00:21
这段代码显示图片用的,在有图片的时候显示没问题,但是在对应的记录没有图片的时候就报错,
<!--#include file="../../mainpage/book_top.asp"-->
<!--#include file="conn.asp"-->
<%
if session("NewsAdmin")=""then
response.write("<script>location.href('index.asp')</script>")
response.end()
end if
%>
<%
set rs=server.createobject("ADODB.recordset")
if request("pid")<> "" then
uid=request("pid")
sql="select * from products_pic where id="&uid
rs.open sql,conn,1,1
response.contenttype="image/gif"
Response.BinaryWrite rs("pic")
'Response.ContentType = "imgge/gif"
'Response.BinaryWrite rs("pic").getChunk(8000000)
rs.close
set rs=nothing
set conn=nothing
end if
%>

错误如下
错误类型:
Response 对象, ASP 0106 (0x80020005)

在rs.open sql,conn,1,1 这句话下边用isnull进行判断你的OLE对象是否为空,为空显示错误,不为空显示图片就成了。。

sql="select * from products_pic where id="&uid
rs.open sql,conn,1,1

if rs.eof and rs.bof then
response '错误,找不到该数据.'
response.end
end if

response.contenttype="image/gif"

在页面开始加一句 On Error Resume Next 即可

'楼主加一判断即可
if 资料库中有图片资料 then
'显示你的图片资料
end if