Академический Документы
Профессиональный Документы
Культура Документы
5/24/2007
By ITtoolbox Popular Q&A Team for ITtoolbox as adapted from VisualBasic-L
discussion group
Summary:
I would like to know how to insert .jpg images from a directory on the hard disk
into an Oracle database. The images to be inserted must be done so with other data
in an Excel sheet. Preferrably, the Excel sheet would have 3 columns of data, with
one of the fields pointing to where the image is stored.
Full Article:
Disclaimer: Contents are not reviewed for correctness and are not endorsed or
recommended by ITtoolbox or any vendor. Popular Q&A contents include summarized
information from VisualBasic-L discussion unless otherwise noted.
In Form Load :
adoCn -> Connection Open
and give iData =1 (change it to any value Later)
Set RS = Nothing
'
strSQL = "Select * from AImage WHERE IMGID=" & iData
Set RS = Nothing
RS.CursorLocation = adUseClient
RS.Open strSQL, adoCn, adOpenKeyset, adLockOptimistic
'
If RS.EOF Then Exit Sub
RS.MoveFirst
'
FileLength = RS("FileLen")
'
Numblocks = FileLength / BlockSize
LeftOver = FileLength Mod BlockSize
'
Me.MousePointer = vbHourglass
'
DiskFile = App.Path & "\image1.jpg"
If Len(Dir$(DiskFile)) > 0 Then
Kill DiskFile
End If
'
DestFileNum = FreeFile
Open DiskFile For Binary As DestFileNum
'
Numblocks = FileLength / BlockSize
LeftOver = FileLength Mod BlockSize
'
ByteData() = RS(1).GetChunk(LeftOver)
Put DestFileNum, , ByteData()
'
For i = 1 To Numblocks
ByteData() = RS(1).GetChunk(BlockSize)
Put DestFileNum, , ByteData()
Next i
'
Close DestFileNum
'
Picture1.Visible = True
Picture1.Picture = LoadPicture(App.Path & "\image1.jpg")
RS.Close
Me.MousePointer = vbNormal
End Sub