如何在asp中读取sql server 中保存的图像?

mikewolf_gkd 2003-01-02 03:48:36
如何在asp中读取sql server 中保存的图像?图像格式为image格式。。。,并在网页
中显示出来,谁有这方面的源码啊?
...全文
61 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
mikewolf_gkd 2003-01-02
  • 打赏
  • 举报
回复
各位高手,我的代码如下:
<!--#include file="const.asp"-->
<%
Response.Expires = 0
Response.Buffer = TRUE
Response.Clear
Response.ContentType = "image/*"
str="select * from xj_xjb where xh='20003104101'"
set rs=dbconn.Execute(str)
Response.BinaryWrite rs("blobdata")
Response.End
%>
我用的是虚拟目录,点http://localhost/asp/showphoto.asp
没有显示图像,但是出现了“文件下载”的对话框,我选择另存,保存成一个
bmp文件,是数据库里的图像,没错,可是为什么不在网页上直接显示出来呢?
高手们,帮忙啊。。。
mikewolf_gkd 2003-01-02
  • 打赏
  • 举报
回复
我上面的程序错误到底在什么地方呢?
mikewolf_gkd 2003-01-02
  • 打赏
  • 举报
回复
我的图象是bmp格式,我用image/*,怎么网页好长时间也没出来图像呢,我的程序为:
<!--#include file="const.asp"-->
<%
Response.Expires = 0
Response.Buffer = TRUE
Response.Clear

Response.ContentType = "image/*"
str="select * from xj_xjb where xh='20003104101'"
set rs=dbconn.Execute(str)
Response.BinaryWrite rs("blobdata")
Response.End
%>
const.asp 是我调用数据库编写的一个函数:
<!--#include file="db.asp"-->
<%
set dbconn=nothing
set dbconn=GetSQLServerConnection("127.0.0.1","sa", "guoyichen","zhjwdb_cz" )
%>
lbd8848 2003-01-02
  • 打赏
  • 举报
回复
Response.ContentType = "image/*"
Response.BinaryWrite Rs("photo")
孟子E章 2003-01-02
  • 打赏
  • 举报
回复
http://www.google.com/search?q=sql+%E5%9B%BE%E7%89%87&ie=UTF-8&oe=UTF-8&hl=zh-CN&btnG=Google%E6%90%9C%E7%B4%A2&lr=
liuqinyi 2003-01-02
  • 打赏
  • 举报
回复
getchunk()

在用ASP编程中,很多时侯要用到图象。对于单纯从数据库中处理一个图象,方法大家讲了很多,也不难,
可以看下面的代码:
这里假设你有个数据库名字叫:PUBS,在数据库中有一个叫:PUB_INFO的表,在表中有一个LOGO的BLOB列。我们查出PUB_ID=0736的人的相片。
FILE: SHOWIMG.ASP
***************************************
<%@ LANGUAGE="VBSCRIPT" %>
<%
' Clear out the existing HTTP header information
Response.Expires = 0
Response.Buffer = TRUE
Response.Clear

' Change the HTTP header to reflect that an image is being passed.
Response.ContentType = "image/gif"

Set cn = Server.CreateObject("ADODB.Connection")
' The following open line assumes you have set up a System DataSource
' by the name of myDSN.
cn.Open "DSN=myDSN;UID=sa;PWD=;DATABASE=pubs"
Set rs = cn.Execute("SELECT logo FROM pub_info WHERE pub_id='0736'")
Response.BinaryWrite rs("logo")
Response.End
%>
*****************************************
执行这个ASP文件就可以看到你存在数据库中的图象了。
但如果是同时处理文字和图象就会有些困难了:-(
比如:一个企业的人员管理,后台数据库可以用SYBASE或SQL SERVER等。(我在这用SQL SERVER)当你在企业内部需要用到BROWSE/SERVER方式,即用浏览器查看员工的个人信息时,就即要处理文字信息同时还要用到关于图象的技巧。
问题在于你显示文字信息时HTML的HEAD中的CONTENT=“TEXT/HTML”,而显示图象则必须是CONTENT=“IMAGE/GIF”或者是CONTENT=”IMAGE/JPEG“。因此你是无法只用一个ASP文件就把文字信息和图象都处理完的,解决的办法是:用一个单独的ASP文件处理图象,然后在处理文字信息的ASP文件中调用这个ASP文件。
在这给大家介绍一个我的解决方法,希望大家一起讨论:
环境:WINNT4.0 SQL SERVER IIS3.0
数据库名:RSDA
表名:RSDA_TABLE
目的:从RSDA_TABLE中查出ID=00001的人员的信息,包括姓名,年龄和照片

第一步:创建一个查询表单RSDA.HTM:
**********************************
<html>
<head>
</head>
<body>
<form method="POST" action="SEARCH.ASP">
<p>请输入编号:<input type="text" name="T1" size="20"><input
type="submit" value="提交" name="B1"><input type="reset" value="复原" name="B2"></p>
</form>
</body>
</html>
***********************************
第二步:建立SEARCH.ASP
***********************************
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=gb2312">
<title>查询结果</title>
</head>
<body bgColor=Azure>

<%
session("RSDA_ID")=Request.Form("T1") '这里我用了一个SESSION变量,是为了在处理图象的ASP文件中再次调用
temp_id=session("RSDA_ID")
<font size=4 color=OrangeRed> 查询结果:</font>
<%set conntemp=server.createobject("adodb.connection")
conntemp.open "dsn=RSDA;uid=sa;pwd=SA"
set rstemp=conntemp.execute("select * from RSDA_TABLE where rsda='"&temp_id&"'")
%>
<% 'put headings on the table of field names
nobody="对不起!在我们的数据库里没有您要找的资料!"%> '判断是否有这个人
<%if rstemp.eof then %>
<font size="5" color=OrangeRed> <%Response.Write(nobody)%></font>
<%else%>
<div align="center">
<center>
<table border="1" width="73%" height="399">
<tr>
<td width="21%" height="49" align="center"><p align="center">姓 名</td>
<td width="30%" height="49" align="center">
<font size=4 color=OrangeRed><%=rstemp(0)%></font></td>
</td>
<tr>
<td width="21%" height="47"><p align="center">年 龄</td>
<td width="30%" height="47" align="center">
<font size=4 color=OrangeRed><%=rstemp(0)%></font></td>
</tr>
<tr>
<td width="49%" height="146" rowspan="3" colspan="2">
<img src="jpg.asp"></td> 'JPG.ASP就是我们将要建立的专门处理图象的ASP文件
</tr>
</table>
</center></div>
rstemp.close
set rstemp=nothing
conntemp.close
set conntemp=nothing
%>
</BODY>
</HTML>
***********************************
第三步:建立处理图象的ASP文件。(JPG.ASP)
***********************************
<%
Response.Expires = 0
Response.Buffer = TRUE
Response.Clear

' Open database
Set conntemp = Server.CreateObject("ADODB.Connection")
conntemp.open "dsn=RSDA;uid=sa;pwd=SA"

'change http header
Response.ContentType = "image/jpeg" ' or "IMAGE/GIF"

' Get picture

TEMP_ID=session("RSDA_ID")
Set Rs = conntemp.Execute("SELECT photo from RSDA_table where ID='"&TEMP_ID&"'")
Response.BinaryWrite Rs("photo")
Session.Abandon
Response.End
%>
**********************************
这里主要就是用到了一个小技巧就是利用了一个SESSION变量来实现两次同条件查询。
大家如我上述只需少量改动,就可以实现一个页面既有文字又有图象了!

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧