Web Development

Our forums are currently in maintenance mode and the ability to post is disabled. We will be back up and running as soon as possible. Thanks for your patience!

General discussion


Image storage in database

By basha.mm ·
How do i store images in database,i am using MS-Access,with VB as frontend?
Also i want to know What should be the size of image?

This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Comments

Collapse -

by ManISKid In reply to Image storage in database

You can specify an 'ole object' which can be many different things which can include images, any one of these can be up to a gigabyte in size.

The northwind database that microsoft tends to leave around has an example of this. I think that if you are using a vb front-end you might need to import the ole packages if you havent already.

Simply, go into the design view for a table, then add or change a field to a 'ole object'.

As for the size of the object, then that depends what you want to use the database for, internet images tend to be around 60k while lan images tend to be 360k.

But it all depends on what the pictures are and how fast the database has to be.

Collapse -

by ahar In reply to Image storage in database

depending on the number of images I whould not save the images directly in the database (size-limit on access) Another way is to store the pictures in a deined directory and ave only the abs/rel path in the database!

Collapse -

by Jaqui In reply to Image storage in database

ahar@ is right.
it's far better to store an uri than to store the image itself.
smaller db size, which keeps it running faster.

Collapse -

by basha.mm In reply to

Poster rated this answer.

Collapse -

by Regg In reply to Image storage in database

It depends if you want to store it as an OLE object or simply in Long Binary format.

Stored as an OLE object means that OLE information is stored with the object and it can be opened with the default application related to the file type (an OLE field is also long binary but other information is store with the object other than just the [picture] object itself).

This is then, when opening the file, dependent on DAO to view the object and means you need either MS ACCESS to view it, or VB and the OLE Object control (not a picture/image control) and only using DAO (not ADO).
In MS ACCESS, or in VB the OLE Control, you can open the table in table view and can double click on it an open it with the application which was defined as have an OLE connection to that file type.
You would not be able to save the object to a file and open it with an external graphic viewer/editor application.
You also would not be able to save it to another DBMS (Database management system i.e. SQL Server, etc.) and retrieve it easily, if at all.

Stored in Long Binary would mean being able to store the object in a JET/ACCESS database, as well as many other DBMSs, in pure long binary format and can retrieve the object data using DAO (if JET DB) or ADO, and even save the object to a file and open it with another graphic viewer/editor application.
You could, in VB for example, show it in a Picture/Image control with-out the need to use the OLE Control.

So, it depends on what your needs are, and if you are using DAO or ADO.
For storing/retrieving a picture as long binary (not OLE long binary) using ADO see the ADO GetChunk and AppendChunk methods. To save the picture form a database long binary field to a file see additionally the ADO Stream object.

Collapse -

by Regg In reply to

Also, if you do store the pictures in a JET/ACCESS database, then use a seperate second database, holding just the picture, (and it's primary key, and maybe creation time and a predefined file name), keeping it away from your main database.

Then you have up to 2 GB of storage. Also try not to store the pictures as Bitmaps as these eat up the available space in the db very fast.
However, you can use more than one seperate db to save the pictures to, and, if the pictures do not relate to the same data table in the main db, then it is easy to use an mdb for each unrelated set of pictures (Employees pictures in one db; pictures of immobilie objects in another; etc.).

Using jpg format and say the pictures average 100kb then each db could hold thousands of pictures, and with ADO can always be easily saved to a file.

I would still assign a file name (w/o path) to the picture data and save it in a second field. Then you have also a uniform name to use if the picture at any time is to be saved to a file.

Collapse -

by harun In reply to Image storage in database

for Save the image in dataBase :
'for declaration section

Dim cn As New ADODB.Connection
Dim rs As ADODB.Recordset
Dim DataFile As Integer, Fl As Long, Chunks As Integer
Dim Fragment As Integer, Chunk() As Byte, i As Integer, FileName As String
Const ChunkSize As Integer = 16384
Const conChunkSize = 100

'for code section

'Open Connection and Record set as per normal

Private Sub cmdSave_Click()



end sub
private sub SavePicture()

Dim strFileNm as string
DataFile = 1
Open strFileNm For Binary Access Read As DataFile
Fl = LOF(DataFile) ' Length of data in file
If Fl = 0 Then Close DataFile: Exit Sub
Chunks = Fl \ ChunkSize
Fragment = Fl Mod ChunkSize
ReDim Chunk(Fragment)
Get DataFile, , Chunk()
rs!logo.AppendChunk Chunk()
ReDim Chunk(ChunkSize)
For i = 1 To Chunks
Get DataFile, , Chunk()
rs!logo.AppendChunk Chunk()
Next i
Close DataFile

'Good Luck

Related Discussions

Related Forums