用asp实现的数据库中存取文件的代码
程序员文章站
2023-11-04 20:42:46
************************************************************************* '** '** ...
*************************************************************************
'**
'** 使用 adodb.stream 保存/读取文件到数据库
'** 引用 microsoft activex data objects 2.5 library 及以上版本
'**
'** ----- 数据库连接字符串模板 ---------------------------------------
'** access数据库
'** iconcstr = "provider=microsoft.jet.oledb.4.0;persist security info=false" & _
'** ";data source=数据库名"
'**
'** sql数据库
'** iconcstr = "provider=sqloledb.1;persist security info=true;" & _
'** "user id=用户名;password=密码;initial catalog=数据库名;data source=sql服务器名"
'**
'*************************************************************************
'
'保存文件到数据库中
sub s_savefile()
dim istm as adodb.stream
dim ire as adodb.recordset
dim iconcstr as string
'数据库连接字符串
iconcstr = "provider=microsoft.jet.oledb.4.0;persist security info=false" & _
";data source=f:\my documents\客户资料1.mdb"
'读取文件到内容
set istm = new adodb.stream
with istm
.type = adtypebinary '二进制模式
.open
.loadfromfile "c:\test.doc"
end with
'打开保存文件的表
set ire = new adodb.recordset
with ire
.open "表", iconc, adopenkeyset, adlockoptimistic
.addnew '新增一条记录
.fields("保存文件内容的字段") = istm.read
.update
end with
'完成后关闭对象
ire.close
istm.close
end sub
'从数据库中读取数据,保存成文件
sub s_readfile()
dim istm as adodb.stream
dim ire as adodb.recordset
dim iconc as string
'数据库连接字符串
iconc = "provider=microsoft.jet.oledb.4.0;persist security info=false" & _
";data source=\\xz\c$\inetpub\zj\zj\zj.mdb"
'打开表
set ire = new adodb.recordset
ire.open "tb_img", iconc, adopenkeyset, adlockreadonly
ire.filter = "id=64"
'保存到文件
set istm = new adodb.stream
with istm
.mode = admodereadwrite
.type = adtypebinary
.open
.write ire("img")
.savetofile "c:\test.doc"
end with
'关闭对象
ire.close
istm.close
end sub
'**
'** 使用 adodb.stream 保存/读取文件到数据库
'** 引用 microsoft activex data objects 2.5 library 及以上版本
'**
'** ----- 数据库连接字符串模板 ---------------------------------------
'** access数据库
'** iconcstr = "provider=microsoft.jet.oledb.4.0;persist security info=false" & _
'** ";data source=数据库名"
'**
'** sql数据库
'** iconcstr = "provider=sqloledb.1;persist security info=true;" & _
'** "user id=用户名;password=密码;initial catalog=数据库名;data source=sql服务器名"
'**
'*************************************************************************
'
'保存文件到数据库中
sub s_savefile()
dim istm as adodb.stream
dim ire as adodb.recordset
dim iconcstr as string
'数据库连接字符串
iconcstr = "provider=microsoft.jet.oledb.4.0;persist security info=false" & _
";data source=f:\my documents\客户资料1.mdb"
'读取文件到内容
set istm = new adodb.stream
with istm
.type = adtypebinary '二进制模式
.open
.loadfromfile "c:\test.doc"
end with
'打开保存文件的表
set ire = new adodb.recordset
with ire
.open "表", iconc, adopenkeyset, adlockoptimistic
.addnew '新增一条记录
.fields("保存文件内容的字段") = istm.read
.update
end with
'完成后关闭对象
ire.close
istm.close
end sub
'从数据库中读取数据,保存成文件
sub s_readfile()
dim istm as adodb.stream
dim ire as adodb.recordset
dim iconc as string
'数据库连接字符串
iconc = "provider=microsoft.jet.oledb.4.0;persist security info=false" & _
";data source=\\xz\c$\inetpub\zj\zj\zj.mdb"
'打开表
set ire = new adodb.recordset
ire.open "tb_img", iconc, adopenkeyset, adlockreadonly
ire.filter = "id=64"
'保存到文件
set istm = new adodb.stream
with istm
.mode = admodereadwrite
.type = adtypebinary
.open
.write ire("img")
.savetofile "c:\test.doc"
end with
'关闭对象
ire.close
istm.close
end sub
上一篇: 几个经典的ASP应用
下一篇: Java程序员需要掌握的英语词组