|
|
Re: Inserting pictures into the Database (Jpeg, BMP, Gif etc.) [message #37688 is a reply to message #36864] |
Thu, 21 February 2002 00:42   |
Kiran Kumar S.
Messages: 1 Registered: February 2002
|
Junior Member |
|
|
Sir,
my Client side program is being developed using Visual Basic 6.0 and I had to insert pictures into database which happens to be Oracle 8i. The pictures are of gif/jpeg format. I can't change my front end. Plase suggest me an idea with, if possible, some coding example.
Thanking you,
Kiran Kumar
Project Executive
BHEL Corporate R&D,
Hyderabad
|
|
|
Re: Inserting pictures into the Database (Jpeg, BMP, Gif etc.) [message #38109 is a reply to message #36864] |
Thu, 21 March 2002 01:07   |
Pradeep
Messages: 55 Registered: July 2000
|
Member |
|
|
Hai
Iam sending this code which would help you to add an image to a dataabse(access and sql server) if u would like to insert it in oracle only driver and datatype changes...
hope this will help you
===============================
VB 5,6 Retrieve an Image From the Database
Listing 1 Retrieve a record from the database and propagate the fields on the form. If the image path is empty, the program assumes that the image is stored as a BLOB. The procedure assumes that you've opened the recordset (rs) and positioned it to the correct record.
==============================================
Public Sub FillFields()
'Propagate fields with record data
Dim lngImageSize As Long
Dim lngOffset As Long
Dim bytChunk() As Byte
Dim intFile As Integer
Dim strTempPic As String
Const conChunkSize = 100
Dim strImage As String
If Not (rs.BOF And rs.EOF) Then
txtImageTitle.Text = _
rs.Fields("ImageTitle")
If Trim$("" & _
rs.Fields("ImagePath")) = "" Then
'Image saved as a BLOB
txtImagePath.Text = ""
optImageType(1).Value = True
'Make sure the temporary file
'does not already exist
strTempPic = App.Path & "TempPic.jpg"
If Len(Dir(strTempPic)) > 0 Then
Kill strTempPic
End If
'Open the temporary file to
'save the BLOB to
intFile = FreeFile
Open strTempPic For Binary As #intFile
'Read the binary data into
'the byte variable array
lngImageSize = _
rs("ImageBLOB").ActualSize
Do While lngOffset < lngImageSize
bytChunk() = rs _
("ImageBLOB").GetChunk(conChunkSize)
Put #intFile, , bytChunk()
lngOffset = lngOffset + conChunkSize
Loop
Close #intFile
'After loading the image, get
'rid of the temporary file
imgDBImage.Picture = _
LoadPicture(strTempPic)
Kill strTempPic
Else 'Image saved as file pointer
txtImagePath.Text = rs.Fields("ImagePath")
optImageType(0).Value = True
If Not IsNull(rs.Fields ("ImagePath")) Then
strImage = Trim$("" & _
rs.Fields("ImagePath"))
If Len(Dir(strImage)) Then
imgDBImage.Picture = _
LoadPicture(strImage)
Else
imgDBImage.Picture = LoadPicture()
End If
End If
End If
End If
End Sub
================================================
Save the Image
==================
Listing 2 Save the record to the database. Depending on the option button selected, save the image to the database as either a file pointer or as a BLOB. The procedure assumes that you either positioned the recordset (rs) to a new record, or that you're editing the current record (rs.Edit).
Private Sub SaveToDB()
Dim bytBLOB() As Byte
Dim strImagePath As String
Dim intNum As Integer
'Save the record
strImagePath = Trim$(txtImagePath.Text)
With rs
.Fields("ImageTitle") = _
Trim$(txtImageTitle.Text)
If (optImageType(0).Value) Then
'Save as file pointer
.Fields("ImagePath") = strImagePath
Else
If (txtImagePath.Text <> "") Then
'Open the picture file
intNum = FreeFile
Open strImagePath For Binary As #intNum
ReDim bytBLOB (FileLen(strImagePath))
'Read data and close file
Get #intNum, , bytBLOB
Close #1
'Store the BLOB
.Fields("ImagePath") = ""
.Fields("ImageBLOB"). _
AppendChunk bytBLOB
End If
End If
.Update
End With
End Sub
|
|
|
|