Home » SQL & PL/SQL » SQL & PL/SQL » Inserting pictures into the Database (Jpeg, BMP, Gif etc.)
Inserting pictures into the Database (Jpeg, BMP, Gif etc.) [message #36864] Fri, 28 December 2001 04:54 Go to next message
Vivek Hemdev
Messages: 1
Registered: December 2001
Junior Member
How do I insert pictures into the database.

----------------------------------------------------------------------
Re: Inserting pictures into the Database (Jpeg, BMP, Gif etc.) [message #36866 is a reply to message #36864] Fri, 28 December 2001 05:42 Go to previous messageGo to next message
Suresh Vemulapalli
Messages: 624
Registered: August 2000
Senior Member
create table with blob datatype.

use dbms_lob package to load images files from server machine file system. If you want to load from client machine then use front end tools like DEVELOPER 6i (Forms).

Suresh

----------------------------------------------------------------------
Re: Inserting pictures into the Database (Jpeg, BMP, Gif etc.) [message #37688 is a reply to message #36864] Thu, 21 February 2002 00:42 Go to previous messageGo to next message
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 Go to previous messageGo to next message
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
Inserting and Retrieve pictures into the Oracle Database (Jpeg, BMP, Gif etc.) [message #42059 is a reply to message #38109] Tue, 25 February 2003 06:06 Go to previous message
shiva
Messages: 38
Registered: March 2001
Member
hello sir,

Also i have the same Problem in VB6 with Oracle.

So please send me the code for store and retrieve the picuters in Oracle through VB6 with Explanation if you wish.
Thanking you.
Previous Topic: Drop Problem
Next Topic: Ora-00936 Missing Expression
Goto Forum:
  


Current Time: Tue Aug 05 00:49:42 CDT 2025