CSDN博客

img playyuer

一段精简的使用 ADODB.Stream 读写"大字段"的 VB 代码!

发表于2001/5/5 13:15:00  1022人阅读

'一段精简的读写"大字段"的代码,使用 ADODB.Stream
'Objects: Form1、Picture1
'引用 Microsoft ActiveX Data Objects 2.5 Libary
'或 Microsoft ActiveX Data Objects 2.6 Libary
Dim TempFileName As String
TempFileName = App.Path & "/TempFile.tmp"
Dim adoConnection As New ADODB.Connection
Dim adoRecordset As New ADODB.Recordset
adoConnection.Open "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=" & App.Path & "/mmxdb97.mdb"
adoRecordset.Open "SELECT * FROM bmp", adoConnection, adOpenKeyset, adLockOptimistic ', adCmdTable
Debug.Print adoRecordset.Fields(1).Type '大字段
adoRecordset.AddNew
Dim adoStream As New ADODB.Stream
adoStream.Type = adTypeBinary
adoStream.Open
adoStream.LoadFromFile CommonDialog1.FileName
'将二进制文件写入大字段:
adoRecordset.Fields.Item(1).AppendChunk adoStream.Read
'================================
'从大字段读取二进制数据:
adoStream.Write adoRecordset.Fields.Item(1).GetChunk(adoRecordset.Fields.Item(1).ActualSize)
adoStream.SaveToFile TempFileName, IIf(Len(Trim(Dir(TempFileName, vbNormal + vbHidden))) > 0, adSaveCreateOverWrite, adSaveCreateNotExist)
Picture1.AutoSize = True
Picture1.Picture = LoadPicture(TempFileName)
0 0

相关博文

我的热门文章

img
取 消
img