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

ASP
ASP系列讲座(十)ASP 内建对象
ASP系列讲座(十一)ActiveX 组件
ASP系列讲座(十二)向浏览器发送内容
ASP系列讲座(十三)向浏览器传送脚本
ASP系列讲座(十四)包含文件
ASP系列讲座(十五)使用 HTML 表格
ASP系列讲座(十六)访问数据库
ASP系列讲座(十七)调试 ASP 脚本
ASP系列讲座(十八)管理应用程序
ASP系列讲座(十九)管理会话
ASP系列讲座(二十)维护 ASP 应用程序的安全
ASP系列讲座(二十一)创建事务性脚本
ASP系列讲座(二十二)使用国际站点
ASP系列讲座(二十三)编写跨平台应用程序
利 用 ISAPI 实 现 向 数 据 库 中 添 加 记 录 (一)
利 用 ISAPI 实 现 向 数 据 库 中 添 加 记 录 (二)
利 用 ISAPI 实 现 向 数 据 库 中 添 加 记 录 (三)
利 用 ISAPI 实 现 向 数 据 库 中 添 加 记 录 (四)
利 用 ISAPI 实 现 向 数 据 库 中 添 加 记 录 (五)
利 用 ISAPI 实 现 向 数 据 库 中 添 加 记 录 (六)

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


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