VB6保存文件到数据库,从数据库保存为文件

这篇博客介绍了如何使用VB6进行文件与数据库之间的交互。通过`SaveToFile`函数将数据库中的文件导出到指定路径,利用`putFile`函数检查文件版本并更新数据库,以及`InsertToTable`函数将文件写入数据库记录。博客中还包含错误处理和文件版本比较的逻辑。
摘要由CSDN通过智能技术生成


' 建立表 Ver 表结构为: f001 标识增量字段,f002 nvarchar(50) 文件名,f003 nvarchar(50) 版本号,f004 image  存储文件,f005 datetime 上传日期时间,f006 存储f004中exe文件的最后修改时间,以上字段均非空
'                      f007 nvarchar(50)SQL文件名称 ,f008 image SQL文件 ,f009 nvarchar(50)控件文件名称,f010 image 控件文件,f011 nvarchar(50)控件注册文件名,f012 image 控件注册文件‘

'保存为文件
Public Sub SaveToFile(ByVal sFileName As String, Field As String)
'
' Export the file from the database to the passed filename
'
    Dim iFileNum As Integer
    Dim lFileLen As Long
    Dim lChunks As Long
    Dim lFragment As Long
    Dim bChunk() As Byte
    Dim lCount As Long
    Dim oField As Field
    Dim oRS As New ADODB.Recordset
    Const CHUNKSIZE As Long = 16384 ' internal chunksize
  
    On Error GoTo ErrorHandler
'
' Get the field from the database
'
    DBOpen oRS, "select * from ver where f001=(select max(f001) from ver)"
       
    If oRS.BOF Or oRS.EOF Then GoTo PROC_EXIT
   
    iFileNum = FreeFile
'
' Create the Named File
'
    Open sFileName For Binary Access Write As iFileNum
   
    Set oField = oRS.Fields(Field)
    '
' Get the length of the file and the number of chunks required

    lFileLen = oF

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值