给一个使用ADODB.Stream读取BLOB字段的范例
时间: 2024-05-02 16:19:18 浏览: 176
Sure, here's an example of using ADODB.Stream to read a BLOB field:
```
Dim conn As New ADODB.Connection
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Data\db.mdb;"
conn.Open
Dim rs As New ADODB.Recordset
rs.Open "SELECT blobField FROM myTable WHERE ID=1", conn, adOpenStatic
Dim stream As New ADODB.Stream
stream.Type = adTypeBinary
stream.Open
stream.Write rs.Fields("blobField").Value
stream.SaveToFile "C:\Data\output.txt", adSaveCreateOverWrite
stream.Close
rs.Close
conn.Close
```
This code opens a connection to a database and selects a single record from a table where ID = 1. It then creates an ADODB.Stream object, sets its type to binary, and writes the contents of the BLOB field to the stream. Finally, it saves the output to a file and closes the stream, recordset, and connection.
I hope this helps!
阅读全文