高分求救:ACCESS中调图形。

我原来是用ODBC联数据库,没问题。如果不用odbc,如何写代码?
下面是用ODBC时的代码(数据库路径:c:\mydb\gin.mdb):

set connGraph=server.CreateObject("ADODB.connection")
connGraph.Open "ttt","",""
set rec=server.createobject("ADODB.recordset")
strsql="select img from tab1 where id=1 "
rec.open strsql,connGraph,1,1
Response.ContentType = "image/*"
Response.BinaryWrite rec("img").getChunk(7500000)
rec.close
set rec=nothing
set connGraph=nothing

我用如下代码不行,也没什么提示错误,就是没图:
set connGraph=server.CreateObject("ADODB.connection")
Strconn="DRIVER={Microsoft Access Driver (.mdb)}; "
Strconn=Strconn & "DBQ=c:\mydb\gin.mdb"
set rec=server.createobject("ADODB.recordset")
connGraph.Open Strconn
strsql="select img from dd where id=1 "
rec.open strsql,connGraph,1,1
Response.ContentType = "image/
"
Response.BinaryWrite rec("img").getChunk(7500000)
rec.close
set rec=nothing
set connGraph=nothing

---------------------------------------------------------------

strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\mydb\gin.mdb"
---------------------------------------------------------------

你将上面的代码保存为showing.asp文件
让后在你要显示图片地方加上一句:

....

1<img height="???" src="showing.asp" width="????"/>

....

如果你要显示数据库中的所有图片,或者某些图片,你可以通过传递一个ID参数来实现
showing.asp中的sql语句要改成:
strsql="select img from images where id=" & trim(request("id"))
这样你在显示图片时语句是:

1<img src="showing.asp?id=1"/>
1<img src="showing.asp?id=2"/>

......

Published At
Categories with Web编程
Tagged with
comments powered by Disqus