通用 文件保存至数据库,从数据库写入磁盘 程序代码
来源:互联网 发布:生日礼物淘宝网 编辑:程序博客网 时间:2024/04/29 10:45
这几天我休假中,正好有时间继续编写mycodelibrary 1.5版,今天晚上刚好写到文件与数据库存入取出模块,在论坛上此问题见的也较多,所以特此公开此部分代码,供有需者参考使用.代码虽然可以完整的正常使用,但还是需要做些错误方面的处理。
'欢迎你下载使用本代码,本份代码由程序太平洋提供下载学习之用
'声明:
'1.本站所有代码的版权归原作者所有,如果你使用了在本站下载的源代码
' 引起的一切纠纷(后果)与本站无关,请您尊重原作者的劳动成果!
'2.若本站在代码上有侵权之处请您与站长联系,站长会及时更正。
'中国代码网:http://www.daima.com.cn
'程序太平洋:http://www.5ivb.net
'email:dapha@etang.com
'copyright 2001-2005 by www.5ivb.net
'整理时间:2004-8-9 3:32:48
option explicit
public objconn as new adodb.connection
public m_connstring as string
private function exists(byval str_filename as string, _
byval int_val as vbfileattribute) as boolean
'--------------------------------------------------------------------------------
' project : mycodelibrary 1.5
' procedure : exists
' description: [判断文件或目录是否存在]
' created by : ronggang (zhouronggang@163.com)
' date-time : 2004-8-9-2:31:45
'
' parameters : str_filename (string)
' int_val (vbfileattribute)
'--------------------------------------------------------------------------------
on error resume next
if len(str_filename) = 0 then
exists = false
exit function
end if
if int_val <> vbdirectory then '如果不是目录
'如果为空表示文件不存在
if dir(str_filename) = "" then
exists = false
else
exists = true
end if
else
if dir(str_filename, vbdirectory) = "" then
exists = false
else
exists = true
end if
end if
end function
public sub binvalue(byval strfilename as string, byref objfield as field)
'--------------------------------------------------------------------------------
' project : mycodelibrary 1.5
' procedure : binvalue
' description: [将文件保存至数据库中]
' created by : wangfeng
' date-time : 2004-8-9-2:20:37
'
' parameters : strfilename (string)
' objfield (field)
'--------------------------------------------------------------------------------
'此方法需要做错误处理,以防文件己打开
dim objstream as stream
if not exists(strfilename, vbnormal) then '如果文件不存则抛出异常
err.raise 50001, "dbfile", "文件不存在!"
exit sub
end if
set objstream = new adodb.stream
with objstream
.type = adtypebinary
.open
.loadfromfile strfilename
objfield.value = .read
end with
set objstream = nothing
end sub
public function binvalue2file(byval strfilename as string, byref objfield as field, optional overwrite as boolean = false) as boolean
'--------------------------------------------------------------------------------
' project : mycodelibrary 1.5
' procedure : binvalue2file
' description: [将数据库中的二进制数据保存为文件]
' created by : wangfeng
' date-time : 2004-8-9-2:22:33
'
' parameters : strfilename (string) 目标文件
' objfield (field) 数据字段名
' overwrite (boolean = false) 是否覆盖现有存在的文件
' true 覆盖 false(默认)不存在时保存
'--------------------------------------------------------------------------------
on error goto errorhander
dim objstream as stream
dim returnmsg as vbmsgboxresult
set objstream = new adodb.stream
with objstream
.type = adtypebinary
.open
.write objfield.value
if overwrite then
.savetofile strfilename, adsavecreateoverwrite
else
.savetofile strfilename, adsavecreatenotexist
end if
end with
binvalue2file = true '保存成功返回true
101:
set objstream = nothing
exit function
errorhander:
binvalue2file = false
goto 101
end function
public function getfilename(byval strpathfilename) as string
dim ipos as long
ipos = vba.instrrev(strpathfilename, "/")
getfilename = mid(strpathfilename, ipos + 1)
end function
public function getpathname(optional strpathname as string) as string
'sfilename = mid(getpathname, ipos + 1)
dim ipos as long
ipos = vba.instrrev(strpathname, "/")
getpathname = mid(strpathname, 1, ipos)
end function
软件截图:
附完整源码:
点击浏览该文件
在使用过程中如有什么问题也可跟贴提出!谢谢。
- 通用 文件保存至数据库,从数据库写入磁盘 程序代码
- 将文件、图片等写入MySql数据库或者从MySql数据库读出(保存文件字段为blog类型)
- VB6保存文件到数据库,从数据库保存为文件
- 从数据库中提取文件到磁盘
- socket通信+数据写入数据库 程序代码
- 从数据库中读取和写入文件
- 文件保存到数据库/从数据库读出写成文件
- 文件保存到数据库/从数据库读出写成文件
- 插入数据读取数据库写入到Text文件保存
- EXCEL文件保存至数据库
- 从数据库中写入XML
- java从Excel文件读取数据到数据库和从读取数据库数据写入Excel
- php实现将文件写入数据库、从数据库读取文件(防止图片上传漏洞)
- 文件保存到数据库
- 数据库保存文件
- 上传文件保存数据库
- 从数据库保存Blob文件存储到本地,via C#
- 从数据库中读取图片文件和将图片和写入到数据库中
- 我是败类
- IBM 全面 Linux 化 改写微软垄断局面进展不顺利
- 微软遭 Linux 严重打击 2005 年收入和利润将降低
- Linux 服务器集群系统
- 我终于给我老婆买了个戒指,虽然它只是一个价格为108RMB的18K镀铂金
- 通用 文件保存至数据库,从数据库写入磁盘 程序代码
- 图片存入数据库
- 从“ShowMe”到“快图”
- 用Visual C#调用Windows API函数
- C#域名查询
- 如何让你的SQL运行得更快 zz
- ASP输出WBMP手机通用图片源码
- ext2文件系统下恢复误删除的文件
- JAVA编程规范