Dim cn As New ADODB.Connection, rs As New ADODB.Recordset
Dim tmpfile As String, FileNum As Integer, tmpByte() As Byte
Dim fileLen As Long, BlockNum As Long, BlockRem As Long, i As Long
Const BLOCKSIZE = 1000
Private Sub Command2_Click()
FileNum = FreeFile()
tmpfile = "e:\aa.bmp"
Open tmpfile For Binary Access Read As FileNum
Open tmpfile For Binary Access Write As FileNum
ReDim tmpByte(BLOCKSIZE)
For i = 1 To BlockNum
tmpByte() = rs.Fields(0).GetChunk(BLOCKSIZE)
Put FileNum, , tmpByte()
Next
If BlockRem > 0 Then
ReDim tmpByte(BlockRem)
tmpByte() = rs.Fields(0).GetChunk(BlockRem)
Put FileNum, , tmpByte()
End If
Dim rs As New ADODB.Recordset
Dim stm As ADODB.Stream
Set stm = New ADODB.Stream
' Skip any table not found errors
On Error Resume Next
cn.Execute "drop table BinaryObject"
On Error GoTo 0
'Create the BinaryObject table
cn.Execute "create table BinaryObject " & _
"(blob_id int IDENTITY(1,1), " & _
"blob_filename varchar(256), " & _
"blob_object image)"
rs.Open "Select * from BinaryObject where 1=2", cn, adOpenKeyset, adLockOptimistic
'Read the binary files from disk
stm.Type = adTypeBinary
stm.Open
stm.LoadFromFile App.Path & "\BLOBsample.jpg"
End Sub
Private Sub DisplayBLOB(cn As ADODB.Connection)
Dim rs As New ADODB.Recordset
' Select the only image in the table
rs.Open "Select * from BinaryObject where blob_id = 1", cn
' Set the DataSource to the recordset
Set imgBinaryData.DataSource = rs
'Set the DataField to the BLOB field
imgBinaryData.DataField = rs!blob_object.Name