将BLOB保存到文档

时间:2019-05-07 13:22:42

标签: vb6 blob

我正在尝试将oracle blob保存为扩展名为.doc的文件, 但出现错误:在oFile行上键入不匹配。写入“ blob content”

试图改变方法,但没有运气

 BlobToFile
    WriteFromBinary
    WriteFromUnsizedBinary
    WriteFromText 
    WriteFromUnsizedText

我的代码:

Private Sub cmdOpenWord_Click()

 oraFile.Connect = Name & "/" & code
 oraFile.DatabaseName = OraDatabase.DatabaseName
 oraFile.RecordSource = SQL
 oraFile.Refresh
 If oraFile.Recordset.RecordCount > 0 Then
     Dim oFile As Object
     Set oFile = fso.CreateTextFile("C:\vba.doc", True, True)
     oFile.Write oraFile.Recordset(1).Value
     oFile.Close
     Set oFile = Nothing
 Else
     No_object.Visible = True
 End If
 End Sub

在监视对象中是oracleblob类型

Watch :: oraFile.Recordset(1).Value :: Variant/Object/IOraBlob :         frmDelete.cmdOpenWord_Click

如果我尝试重写而又遇到另一个错误,则看起来像Visual Basic语言没有被Visual Basic所支持。

Sub BlobToFile(ByVal dr As IDataReader, ByVal fieldIndex As Integer, ByVal filename As String)
Const CHUNK_SIZE As Integer = 200
Dim buffer(CHUNK_SIZE - 1) As Byte
Set stream = CreateObject("Scripting.FileSystemObject")
Dim index As Long
index = 0
Try
    Do
        ' Get the next chunk, exit if no more bytes.
        Dim length As Integer
        length = CInt(dr.GetBytes(fieldIndex, index, buffer, 0, CHUNK_SIZE))
        If length = 0 Then Exit Do
        ' Write to file and increment index in field data.
        stream.Write (buffer, 0, length)
        index = index + length
    Loop
Finally
    stream.Close
    End
End Sub

错误消息:编译错误:用户定义的类型未定义

1 个答案:

答案 0 :(得分:0)

尝试 ADODB.Stream

Dim stm As New ADODB.Stream
With stm
    .Open
    .Type = adTypeBinary
    .Write oraFile.Recordset(1)
    .SaveToFile "D:\vba.doc", adSaveCreateOverWrite
End With
stm.Close
Set stm = Nothing


,然后尝试将其保存在另一个文件夹或驱动器中,有时Windows无法将其保存在系统驱动器中。