标题:求一个如何用ASP代码实现以二进制形式存储在ACCESS数据库多张图片滚动的显示 ...
只看楼主
geshou_mhc
Rank: 1
等 级:新手上路
帖 子:20
专家分:0
注 册:2010-3-8
结帖率:50%
已结贴  问题点数:20 回复次数:12 
求一个如何用ASP代码实现以二进制形式存储在ACCESS数据库多张图片滚动的显示
我已经上传了几张图片,数据库里也有了图片的二进制信息,我下面这段代码只能显示一张,请问如何显示多张图片.我的表images,id,类型自动编号,img,类型OLE.还有个问题,我如果在加两个字段title,文本类型,name,文本类型,想做为标题,和内容.该如何写代码呢?在网上找了很久都没解决,大家不要建议我传到文件夹下,路径存入数据库哦,我只想弄懂这个问题.请高手指点,最好能给出详细的代码.谢谢.我是新手而已.好了,我给出upload.asp下面代码:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<%
response.buffer=true
formsize=request.totalbytes
formdata=request.binaryread(formsize)
bncrlf=chrB(13) & chrB(10)
divider=leftB(formdata,clng(instrb(formdata,bncrlf))-1)
datastart=instrb(formdata,bncrlf & bncrlf)+4
dataend=instrb(datastart+1,formdata,divider)-datastart
mydata=midb(formdata,datastart,dataend)
Set connGraph=Server.CreateObject("ADODB.Connection")
connGraph.Open "Dbq=" & Server.Mappath("wwwlink.mdb") & ";Driver={Microsoft Access Driver (*.mdb)}"
set rec=server.createobject("ADODB.recordset")
rec.Open "SELECT * FROM images where id is null",connGraph,1,3
rec.addnew
rec("img").appendchunk mydata
rec.update
rec.close
set rec=nothing
set connGraph=nothing
%>

</body>
</html>
shou.asp代码如下:
<html>
<head>
<title>无标题文档</title>
</head>
<body>

<%
Response.Expires = 0
Response.buffer=True
Response.clear  
Dim connGraph,strsql,rec                  
Set connGraph=Server.CreateObject("ADODB.Connection")
connGraph.Open "Dbq=" & Server.Mappath("wwwlink.mdb") & ";Driver={Microsoft Access Driver (*.mdb)}"
set rec=server.createobject("ADODB.recordset")
id=trim(request.querystring("id"))
strsql="select img from images where id=id"
rec.Open strsql,connGraph,1,1
Response.ContentType="image/*"
Response.BinaryWrite rec("img").getChunk(7500000)
rec.close
set rec=nothing
set connGraph=nothing
%>
</body>
</html>
dispic.asp代码如下:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<%
 '以下连接数据库,建立一个Connection对象实例conn
 'Dim conn,strConn
 Set connGrap=Server.CreateObject("ADODB.Connection")
 strConn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("wwwlink.mdb")
 connGrap.Open strConn
 Dim rs,sql
 %>
 

<table width="40%" border=0 align=center cellpadding=0 cellspacing="0" cellspace="0">
<tr>
<td>
<%
set rs=server.CreateObject("adodb.Recordset")
sql="select * from images order by id DESC"
rs.open sql,connGrap,1,1
%>
<img src="show.asp?id="&rs("id")&"">
</td>
</tr>
</table>
</body>
</html>
搜索更多相关主题的帖子: 形式 数据库 ASP ACCESS 二进制 
2010-03-08 23:05
geshou_mhc
Rank: 1
等 级:新手上路
帖 子:20
专家分:0
注 册:2010-3-8
得分:0 
没有人会吗?帮忙解决一下,在等待中啊,谢谢了
2010-03-08 23:27
geshou_mhc
Rank: 1
等 级:新手上路
帖 子:20
专家分:0
注 册:2010-3-8
得分:0 
看来这里没什么人气哦,看的人多,回答的少之又少.还是没什么人会啊
2010-03-08 23:51
aspic
Rank: 17Rank: 17Rank: 17Rank: 17Rank: 17
等 级:贵宾
威 望:51
帖 子:2258
专家分:8050
注 册:2008-2-18
得分:14 
基础的循环 看下置顶帖子
2010-03-09 09:25
geshou_mhc
Rank: 1
等 级:新手上路
帖 子:20
专家分:0
注 册:2010-3-8
得分:0 
在show.asp代码里加吗?
<%
Response.Expires = 0
Response.buffer=True
Response.clear  
Dim connGraph,strsql,rec                  
Set connGraph=Server.CreateObject("ADODB.Connection")
connGraph.Open "Dbq=" & Server.Mappath("wwwlink.mdb") & ";Driver={Microsoft Access Driver (*.mdb)}"
set rec=server.createobject("ADODB.recordset")
id=trim(request.querystring("id"))
strsql="select img from images where id=id"
rec.Open strsql,connGraph,1,1
Do While Not rec.Eof
Response.ContentType="image/*"
Response.BinaryWrite rec("img").getChunk(7500000)
rec.MoveNext
Loop
rec.close
set rec=nothing
set connGraph=nothing
%>
这样不行啊,出错,可以详细点吗?你把代码复制下来帮我加好吧.谢谢了
2010-03-09 10:20
geshou_mhc
Rank: 1
等 级:新手上路
帖 子:20
专家分:0
注 册:2010-3-8
得分:0 
我也用过循环代码,但是可以显示多张,并且都是同一张而已.其实就是第一张的重复出现,我想显示不同的图片,因为我已经上传了几张不同的图片了.
2010-03-09 10:45
geshou_mhc
Rank: 1
等 级:新手上路
帖 子:20
专家分:0
注 册:2010-3-8
得分:0 
哪位高人能帮我实现这个功能呢?万分感激,真的是找了一个星期了,都找不到答案,因该是用where语句实现的就是不知道怎么写才能实现.
2010-03-09 10:48
aspic
Rank: 17Rank: 17Rank: 17Rank: 17Rank: 17
等 级:贵宾
威 望:51
帖 子:2258
专家分:8050
注 册:2008-2-18
得分:0 
程序代码:
<%
If Request("Action")="post" Then
    response.buffer=true
    formsize=request.totalbytes
    formdata=request.binaryread(formsize)
    bncrlf=chrB(13) & chrB(10)
    divider=leftB(formdata,clng(instrb(formdata,bncrlf))-1)
    datastart=instrb(formdata,bncrlf & bncrlf)+4
    dataend=instrb(datastart+1,formdata,divider)-datastart
    mydata=midb(formdata,datastart,dataend)
    Set connGraph=Server.CreateObject("ADODB.Connection")
    connGraph.Open "Dbq=" & Server.Mappath("../Data/#Data.mdb") & ";Driver={Microsoft Access Driver (*.mdb)}"
    set rec=server.createobject("ADODB.recordset")
    rec.Open "SELECT * FROM images",connGraph,1,3
    rec.addnew
    rec("img").appendchunk mydata
    rec.update
    rec.close
    set rec=nothing
    set connGraph=nothing
End If
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.>
<html xmlns="http://www.>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>
<form action="?Action=post" method="post" enctype="multipart/form-data">
    <input type="file" name="mefile"><br>
    <input type="submit" name="ok" value="OK">
</form>
<a href="b.asp">显示</a>
</body>
</html>

程序代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.>
<html xmlns="http://www.>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>
<%
set connGraph=server.CreateObject("ADODB.connection")
connGraph.ConnectionString="driver={Microsoft Access Driver (*.mdb)};DBQ=" &server.MapPath("../Data/#Data.mdb")
connGraph.Open
set rec=server.createobject("ADODB.recordset")
strsql="select id from images"
rec.open strsql,connGraph,1,1
do while not rec.eof
    Response.Write "<img src=""img.asp?id="&rec(0)&""" />"
rec.movenext
loop
rec.close
set rec=nothing
set connGraph=nothing
%>
</body>
</html>

程序代码:
<%
set connGraph=server.CreateObject("ADODB.connection")
connGraph.ConnectionString="driver={Microsoft Access Driver (*.mdb)};DBQ=" &server.MapPath("../Data/#Data.mdb")
connGraph.Open
set rec=server.createobject("ADODB.recordset")
strsql="select img from images where id=" & trim(request("id"))
rec.open strsql,connGraph,1,1
Response.ContentType = "image/*"
Response.BinaryWrite rec("img").getChunk(7500000)
rec.close
set rec=nothing
set connGraph=nothing
%>
2010-03-09 10:55
aspic
Rank: 17Rank: 17Rank: 17Rank: 17Rank: 17
等 级:贵宾
威 望:51
帖 子:2258
专家分:8050
注 册:2008-2-18
得分:0 
输出的图片只能通过<img src= />这样的方式来显示 明白?
2010-03-09 10:56
geshou_mhc
Rank: 1
等 级:新手上路
帖 子:20
专家分:0
注 册:2010-3-8
得分:0 
明白的,那个我没放上去而已,我另做了一个界面,谢谢哦,我试试先,有问题再问你.
2010-03-09 11:53



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-298872-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.817130 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved