大家帮我看看为什么不执行到这个文件,急!!
dmgf 2002-12-10 01:01:13 我要把图片和文字混合输出,图片和文字都存在sqlserver中,按照通常的说法,输出图片要独立用一个asp文件,我把这个文件照着例子抄了下来,起名为GetImg.asp
然后在另一asp文件(起名为图文显示.asp)中写
<% response.write "<img src=""GetImg.asp?id=1"">" %>
但它就是不执行GetImg.asp中的代码(或者说,根本没进去执行getimg.asp),但网上和书上都推荐这种写法的,何故?如果改写?很急,谢谢
完整的代码如下,请各位多多指点。
1.Table的脚本:
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[tblImageNews]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[tblImageNews]
GO
CREATE TABLE [dbo].[tblImageNews] (
[fldID] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[fldImg] [image] NULL ,
[fldHead] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[fldText] [ntext] COLLATE Chinese_PRC_CI_AS NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
2.图文显示.asp的代码
<% @LANGUAGE="VBSCRIPT" %>
<% Option Explicit %>
<%
dim adoc,ador
dim strDsn,strSql
dim strHead,strText
strDsn="provider=sqloledb.1;uid=sa;pwd=;server=admin;database=dbnano"
set adoc=server.createobject("adodb.connection")
set ador=server.createobject("adodb.recordset")
adoc.open strDsn
strsql="select * from tblImageNews where fldID='1'"
ador.open strsql,adoc,1,1
if ador.bof and ador.eof then
SzMsg="操作失败,请稍后重试。"
else
strHead=ador.fields("fldHead")
strText=ador.fields("fldText")
end if
ador.close
set ador=nothing
adoc.close
set adoc=nothing
%>
<html>
<head>
<title>图文显示</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<table width="75%" border="1">
<tr>
<td height="25"><%=strHead%></td>
</tr>
<tr>
<td height="81"> </td>
</tr>
<tr>
<td height="107"><%
response.write "<img src=""GetImg.asp?id=1"">"
%></td>
</tr>
<tr>
<td height="352"><%=strText%></td>
</tr>
</table>
</body>
</html>
3.GetImg.asp代码
<% @LANGUAGE="VBSCRIPT" %>
<% Option Explicit %>
<%
dim adoc,ador
dim strDsn,strSql
Response.Expires=0
response.buffer=true
response.clear
strDsn="provider=sqloledb.1;uid=sa;pwd=;server=admin;database=dbnano"
set adoc=server.createobject("adodb.connection")
set ador=server.createobject("adodb.recordset")
adoc.open strDsn
strsql="select fldImg from tblImageNews where fldID='" & request("id") & "'"
ador.open strsql,adoc,1,1
if ador.bof and ador.eof then
SzMsg="操作失败,请稍后重试。"
else
if ador("fldImg").actualSize>0 then
response.contenttype="image/gif"
response.binarywrite ador.fields("fldImg").getChunk(ador.fields("fldImg").actualSize)
end if
end if
ador.close
set ador=nothing
adoc.close
set adoc=nothing
end sub
%>