定义的表结构:表名称:manman
字段:
NAME VARCHAR2(100)
PIC BLOB
LEN LONG使用ADO2.0文件到ADO字段的子函数如下:Public Function FileToColumn(Col As ADODB.Field, DiskFile As String) As Boolean
On Error GoTo ErrorHandler
FileToColumn = False
'moves a disk file to a ChunkRequired column in the table
'A Byte array is used to avoid a UNICODE string
Dim ByteData() As Byte 'Byte array for LongVarBinary
Dim strData As String 'String for LongVarChar
Dim Numblocks As Integer
Dim FileLength As Long
Dim LeftOver As Long
Dim SourceFile As Integer
Dim i As Integer
Dim BlockSize As Long '表示数据块的大小
BlockSize = 102400
SourceFile = FreeFile
Open DiskFile For Binary Access Read As SourceFile
FileLength = LOF(SourceFile) ' Get the length of the file
If FileLength = 0 Then
Close SourceFile
mStrMsg = DiskFile & " empty or not found."
GoTo CleanExit
Else
' Calculate number of blocks to read and left over bytes
Numblocks = FileLength \ BlockSize
LeftOver = FileLength Mod BlockSize
Col = Null '先将其置为空
Select Case Col.Type
Case adLongVarChar
'Read the 'left over' amount of LONGVARCHAR data
strData = String(LeftOver, " ")
Get SourceFile, , strData
Col.AppendChunk strData
strData = String(BlockSize, " ")
For i = 1 To Numblocks
Get SourceFile, , strData
Col.AppendChunk strData
Next i
Close SourceFile
Case adLongVarBinary
' Read the left over amount of LONGVARBINARY data
ReDim ByteData(FileLength)
Get SourceFile, , ByteData()
Col.AppendChunk ByteData()
'ReDim byteData(BlockSize)
For i = 1 To Numblocks
Get SourceFile, , ByteData()
Col.AppendChunk ByteData()
Next i
Close SourceFile
Case Else
mStrMsg = "not a chunkrequired column."
GoTo CleanExit
End Select
End If
RightExit:
FileToColumn = True
CleanExit:
Exit Function
ErrorHandler:
FileToColumn = False
mStrMsg = "FileToColumn: 发生意外错误 " & mStrMsg & vbCrLf & Err.Description
On Error GoTo 0
End Function写入的函数:
Private Sub cmdAdd_Click()
Dim strName As String
strName = InputBox("请输入人名:")
mRst.AddNew
mRst.Fields("name") = strName
If Not mFileCol.FileToColumn(mRst.Fields("pic"), "J:\ZzhDocs\My-Pictur\1085360.jpg") Then
MsgBox mFileCol.mStrMsg
End If
mRst.Fields("len") = mRst.Fields("pic").ActualSize
mRst.Update '?????????????
'mRst.UpdateBatch
End Sub结果集打开参数如下:
Set mRst = New ADODB.Recordset
mRst.CursorType = adOpenKeyset
mRst.LockType = adLockOptimistic
mRst.Open "select * from manman", mCn问题是,我在 mRst.Update '????????????? 处设置断点,察看更新过程,发现一执行Update 结果集中Pic字段的信息就都没了,执行前能够清楚看到Pic的数据块信息,执行后变成空?什么原因?都快晕菜了请执教!这段代码我和微软的文档(使用ADO对Oracle数据库进行图片的操作)进行详细的比较,没什么区别。
字段:
NAME VARCHAR2(100)
PIC BLOB
LEN LONG使用ADO2.0文件到ADO字段的子函数如下:Public Function FileToColumn(Col As ADODB.Field, DiskFile As String) As Boolean
On Error GoTo ErrorHandler
FileToColumn = False
'moves a disk file to a ChunkRequired column in the table
'A Byte array is used to avoid a UNICODE string
Dim ByteData() As Byte 'Byte array for LongVarBinary
Dim strData As String 'String for LongVarChar
Dim Numblocks As Integer
Dim FileLength As Long
Dim LeftOver As Long
Dim SourceFile As Integer
Dim i As Integer
Dim BlockSize As Long '表示数据块的大小
BlockSize = 102400
SourceFile = FreeFile
Open DiskFile For Binary Access Read As SourceFile
FileLength = LOF(SourceFile) ' Get the length of the file
If FileLength = 0 Then
Close SourceFile
mStrMsg = DiskFile & " empty or not found."
GoTo CleanExit
Else
' Calculate number of blocks to read and left over bytes
Numblocks = FileLength \ BlockSize
LeftOver = FileLength Mod BlockSize
Col = Null '先将其置为空
Select Case Col.Type
Case adLongVarChar
'Read the 'left over' amount of LONGVARCHAR data
strData = String(LeftOver, " ")
Get SourceFile, , strData
Col.AppendChunk strData
strData = String(BlockSize, " ")
For i = 1 To Numblocks
Get SourceFile, , strData
Col.AppendChunk strData
Next i
Close SourceFile
Case adLongVarBinary
' Read the left over amount of LONGVARBINARY data
ReDim ByteData(FileLength)
Get SourceFile, , ByteData()
Col.AppendChunk ByteData()
'ReDim byteData(BlockSize)
For i = 1 To Numblocks
Get SourceFile, , ByteData()
Col.AppendChunk ByteData()
Next i
Close SourceFile
Case Else
mStrMsg = "not a chunkrequired column."
GoTo CleanExit
End Select
End If
RightExit:
FileToColumn = True
CleanExit:
Exit Function
ErrorHandler:
FileToColumn = False
mStrMsg = "FileToColumn: 发生意外错误 " & mStrMsg & vbCrLf & Err.Description
On Error GoTo 0
End Function写入的函数:
Private Sub cmdAdd_Click()
Dim strName As String
strName = InputBox("请输入人名:")
mRst.AddNew
mRst.Fields("name") = strName
If Not mFileCol.FileToColumn(mRst.Fields("pic"), "J:\ZzhDocs\My-Pictur\1085360.jpg") Then
MsgBox mFileCol.mStrMsg
End If
mRst.Fields("len") = mRst.Fields("pic").ActualSize
mRst.Update '?????????????
'mRst.UpdateBatch
End Sub结果集打开参数如下:
Set mRst = New ADODB.Recordset
mRst.CursorType = adOpenKeyset
mRst.LockType = adLockOptimistic
mRst.Open "select * from manman", mCn问题是,我在 mRst.Update '????????????? 处设置断点,察看更新过程,发现一执行Update 结果集中Pic字段的信息就都没了,执行前能够清楚看到Pic的数据块信息,执行后变成空?什么原因?都快晕菜了请执教!这段代码我和微软的文档(使用ADO对Oracle数据库进行图片的操作)进行详细的比较,没什么区别。
VB访问BLOB字段帖子应该很多,而且微软网站有两个标准例子,你可以看一下