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

急求助!关于从ACCESS数据库中读取图片的问题
我是用ASP程序往数据库中存储的图片,类型是长二进制型,但是却不能正常显示在网页上,只是显示一个叉,不知道是因为什么?请高手帮忙!谢谢啦!!!我的读取图片的ASP源程序如下: <title> 显示图片 </title> <%  
Response.Buffer   =   True
<!--   #include   file= "adovbs.inc "   -->
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   id= "   &   trim(request( "id "))  
rec.open   strsql,connGraph,3,1  
if   not   rec.eof   then
Response.ContentType   =   "image/gif "  
picsize=rec( "img ").ActualSize
Response.BinaryWrite   rec( "img ").getChunk(picsize)  
rec.close  
else
response.write   "数据库中没有图片! "
end   if
set   rec=nothing  
set   connGraph=nothing  
%>

------解决方案--------------------
Index.asp:

<html>
<body>
<img src= "Show.asp?Id=100 ">
</body>
</html>

Show.asp:

<%
Response.Buffer = True
<!-- #include file= "adovbs.inc " -->
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 id= " & trim(request( "id "))
rec.open strsql,connGraph,3,1
if not rec.eof then
Response.ContentType = "image/gif "
Response.BinaryWrite rec( "img ")
rec.close
else
response.write "数据库中没有图片! "
end if
set rec=nothing
set connGraph=nothing
%>