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

ASP
Microsoft 脚本编码器(3) --- 使用脚本编码器
WAP中的ASP技术(一)
WAP中的ASP技术(二)
WAP中的ASP技术(三)
WAP中的ASP技术(四)
在ADO使用SELECT语法一
在ADO使用SELECT语法二
在ADO使用SELECT语法三
在ADO使用SELECT语法四
在ADO使用SELECT语法五
在ADO使用SELECT语法六
Asp+语法介绍(六)----数据库篇
vbscript错误代码及对应解释大全
ASP系列讲座(三)创建 ASP 页
ASP系列讲座(四)使用脚本语言
ASP系列讲座(五)使用变量和常量
ASP系列讲座(六)编写过程
ASP系列讲座(七)使用组件和对象
ASP系列讲座(八)使用集合
ASP系列讲座(九)设置对象作用域

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 35 ::
收藏到网摘: 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
%>