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

发表于:2007-05-25来源:作者:点击数: 标签:一段ADODB.Stream读写精简使用
'一段精简的读写"大字段"的代码,使用 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
'一段精简的读写"大字段"的代码,使用 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)

原文转自:http://www.ltesting.net