Private Sub Command1_Click()
'把一个文件写入到数据库里
'工程流程:
'指定Rfile对象的为adTypeBinary
'打开
'加载文件
'查询记录
'新增记录
Dim Conn As New ADODB.Connection
Dim Rs As New ADODB.Recordset
Dim Rfile As New ADODB.Stream
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/db1.mdb;Persist Security Info=False"
Rfile.Type = adTypeBinary
Rfile.Open
Rfile.LoadFromFile "c:/1.cel"
Rs.Open "Select * from 表1", Conn, adOpenDynamic, adLockOptimistic
Rs.AddNew
Rs!file = Rfile.Read
Rs.Update
Rs.Close
Conn.Close
End Sub
Private Sub Command2_Click()
'从数据库里读取一记录,在硬盘上建立文件
Dim Conn As New ADODB.Connection
Dim Rs As New ADODB.Recordset
Dim Rfile As New ADODB.Stream
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/db1.mdb;Persist Security Info=False"
Rs.Open "Select top 1 * from 表1", Conn, adOpenDynamic, adLockOptimistic
Rfile.Type = adTypeBinary
Rfile.Open
Rfile.Write Rs!file
Rfile.SaveToFile "c:/2.cel", adSaveCreateOverWrite
Rs.Close
Conn.Close
End Sub
博客展示了将文件写入数据库和从数据库读取记录并建立文件的代码实现。通过指定Rfile对象类型、打开连接、加载文件、查询和新增记录等步骤完成文件写入;通过读取记录、写入流并保存到文件完成读取操作,使用了ADODB相关对象。
1925

被折叠的 条评论
为什么被折叠?



