日期:2014-05-17  浏览次数:20989 次

ASP中的判断语句不起作用
为何我的判断语句不起作用呢?就是在数据库中没有图片时也不会显示那句 "数据库中没有图片 ",请高手指点!谢谢!源代码如下: <%  
set   connGraph=server.CreateObject( "ADODB.connection ")  
connGraph.Open   "Provider=Microsoft.Jet.OLEDB.4.0;Data   Source= "   &   server.mappath( "images.mdb ")   &   ";   Jet   OLEDB:Database  
Password=;   Persist   Security   Info=False; "
set   rec=server.createobject( "ADODB.recordset ")  
strsql= "select   img   from   images   where   imgID= "   &   trim(request( "imgID "))  
rec.open   strsql,connGraph,1,1  
if   not   rec.eof   then
Response.ContentType   =   "image/* "  
picsize=rec( "img ").ActualSize
Response.BinaryWrite   rec( "img ").getChunk(picsize)  
rec.close  
else
response.write   "数据库中没有图片! "
end   if
set   rec=nothing  
set   connGraph=nothing  
%>

------解决方案--------------------
: <%
set connGraph=server.CreateObject( "ADODB.connection ")
connGraph.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & server.mappath( "images.mdb ") & "; Jet OLEDB:Database
Password=; Persist Security Info=False; "
set rec=server.createobject( "ADODB.recordset ")
strsql= "select img from images where imgID= " & trim(request( "imgID "))
rec.open strsql,connGraph,1,1
onsymbol=0
'建立逻辑变量
if rec.recordcount <> 0 then
if not(isnull(rec( "img "))) then
Response.ContentType = "image/* "
picsize=rec( "img ").ActualSize
Response.BinaryWrite rec( "img ").getChunk(picsize)
onsymbol=1
end if
end if
if onsymbol=0 then
response.write "数据库中没有图片! "
end if
rec.close
set rec=nothing
set connGraph=nothing
%>
------解决方案--------------------
你应该整个 "数据库中没有图片 "的图片放到一个表里

如果没有记录就返回这个图片的二进制数据,再用Response.BinaryWrite输出