当前位置: 首页 > 图文教程 > 网络编程 > ASP > ASP中从数据库读取二进制文件数据代码

ASP
在ASP程序中实现数据库事务控制
怎样开始一个ASP网站的设计
ASP中使用ServerVariables集合详解
关于解决商务平台ASP程序的源代码泄漏设想与思考
ASP通用模板类
javascript利用xmlhttp获得服务器时钟的方法
asp+oracle分页程序类(XDOWNPAGE2.0)
ASP中实现小偷程序的原理和简单
asp中vbscript访问xml文件
ASP防SQL注入攻击程序
用ASP读INI配置文件的函数
asp实现关键词获取(各搜索引擎,gb2312及utf-8)
xmlhttp组件获取远程文件并筛选出目标数据
XMLHTTP Get HTML页面时的中文乱码之完全客户端Script解决方案
WEB打印设置解决方案一(通过修改注册表改变IE打印设置)
WEB打印设置解决方案二(利用ScriptX.cab控件改变IE打印设置)
WEB打印设置解决方案三(FileSystem组件实现WEB打印)
WEB打印设置解决方案四(在ASP中实现网络打印功能)
ASP实用技巧 强制刷新网页
Access通用-自动替换数据库中的字符串

ASP中从数据库读取二进制文件数据代码


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 28 ::
收藏到网摘: n/a

 

<%
driver_name1="DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=D:\数据库\TREE.MDB"    '根目录下数据库打开语句

  dim search,rs,j
  search="select * from Files where ID=" & request.querystring("ID")
  set my_conn=server.CreateObject ("adodb.connection")
  my_conn.open driver_name1
  set rs=Server.CreateObject("ADODB.Recordset")
  rs.Open search,my_conn,1,3
  if rs.bof or rs.eof then
    response.write "错误:找不到该文件"
    response.end
  end if

'设置文件的大小及MIME类型
Function SetForDisplay(field, contentType)
contentType = LCase(trim(contentType))
nFieldSize = field.ActualSize
bytes = field.GetChunk(nFieldSize)
Session("Bytes") = bytes
Session("Type") = contentType
End Function

   SetForDisplay RS("File"),rs("FileType")
   'Response.AddHeader "Content-Disposition", "attachment; filename=" & rs("FileName")
   response.contentType = Session("Type")
   response.BinaryWrite Session("Bytes")
   Session("Type") = ""
   Session("Bytes") = ""

  set rs=nothing
  my_conn.close
  set my_conn=nothing
%>