网络编程
位置:首页>> 网络编程>> Asp编程>> asp如何从数据库中调出个人档案?

asp如何从数据库中调出个人档案?

 来源:asp之家 发布时间:2009-11-15 20:02:00 

标签:数据库,相片,图像,asp

我正在开发一个档案管理系统,需要从数据库中同时调出图像及相关的文字说明,可我只做到了单纯地显示图片,像有一个数据库CHUNFENG,在数据库中有一个叫CHUNF_INFO的表,表中有一个WORK的NAME列,查出CHUNF_ID=6806的人的相片:

<%@ LANGUAGE="VBSCRIPT" %>
<%
Response.Expires = 0
Response.Buffer = TRUE
Response.Clear
' 清除存在的HTTP表头信息
Response.ContentType = "image/gif"
' 更改表头信息映射被选出的图片
Set cn = Server.CreateObject("ADODB.Connection")
cn.Open "DSN=myDSN;UID=sa;PWD=;DATABASE=chunfeng"
Set rs = cn.Execute("SELECT work FROM chunf_INFO WHERE chunf_id='6806''")
Response.BinaryWrite rs("work")
Response.End
%>

显示图象需要CONTENT="IMAGE/GIF"或CONTENT="IMAGE/JPEG"语句,而显示文字信息HTML的HEAD中的语句为CONTENT="TEXT/HTML",显然,我们无法同时用一个ASP文件就把文字信息和图象都处理完。该如何做呢?

我们的处理技巧是,解决的办法是:用一个单独的ASP文件处理图象,然后在处理文字信息的ASP文件中调用这个处理图像的文件。假设SQL SERVER数据库CHUNFENG,存在表名CHUNF_TABLE,我们要从CHUNF_TABLE中查出ID=88510的人员的信息,包括姓名、年龄和照片:

chunfeng.htm

' 创建查询表单
<html>
<head>
</head>
<body>
<form method="POST" action="SEARCH.ASP">
<p>请输入编号:<input type="text" name="T1" size="20"><inputtype="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("CHUNFENG_ID")=Request.Form("T1") 
' 注意这个session变量,在images.asp图象处理文件中再次被调用 
temp_id=session("CHUNFENG_ID")
<font size=4 color=OrangeRed>查询结果:</font>
<%set conntemp=server.createobject("adodb.connection")
conntemp.open "dsn=CHUNFENG;uid=sa;pwd=SA"
set rstemp=conntemp.execute("select * from CHUNF_TABLE where 
chunfeng=''"&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="images.asp"></td> 
</tr>
</table>
</center></div>
rstemp.close
set rstemp=nothing
conntemp.close
set conntemp=nothing
%>
</BODY>
</HTML>

images.asp

' 处理图象
<%
Response.Expires = 0
Response.Buffer = TRUE
Response.Clear
Set conntemp = Server.CreateObject("ADODB.Connection")
conntemp.open "dsn=CHUNFENG;uid=sa;pwd=SA"
' 打开数据库
Response.ContentType = "image/jpeg" '' or "IMAGE/GIF"
' 更改表头信息
TEMP_ID=session("CHUNFENG_ID")
Set Rs = conntemp.Execute("SELECT photo from CHUNF_TABLE where 
ID=''"&TEMP_ID&"''")
Response.BinaryWrite Rs("photo")
' 获取图像
Session.Abandon 
Response.End
%>

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com