Delphi Pages Forums

Delphi Pages Forums (
-   General (
-   -   insert a image into a microsoft access database (

Josh 02-23-2010 05:09 PM

insert a image into a microsoft access database

i am currently using delphi 2007, i am wanting to be able to add a image(prefrebly jpeg) into a access database. i have tried doing this but i cant as it does not insert correctly, has anyone made any code or anything similar to this to help me out?

this is the code i am currently using to add it to the database

with adotable1 do
(fieldbyName('Picture') as Tblobfield).loadfromFile(opendialog1.filename);

this is the code i am using where i am wanting to search my files for an image and then i want it to be inserted into the database, however i get the error message saying my bitmap is not valid....

what do i do to solve this issue?

thanks in advance.

MrBaseball34 02-24-2010 01:21 PM

What is the Access FieldType for the Picture field?

Josh 02-24-2010 08:06 PM

i set it as an OLE image.

MrBaseball34 02-24-2010 09:16 PM

Have you seen this article?

Josh 02-24-2010 09:47 PM

yes, ive just tried using that, but i could not get it to work as i dont have the rx library.
anyway i figured out how to add an image to a database, however it is saved as long binary data, how do i load this in delphi? i have no idea how to make this work.

MrBaseball34 02-25-2010 01:36 AM

Let me check out some other things.

delphimpd 02-25-2010 05:58 AM

Hi and hope it helps

I use this in MSSQL but it should also work in ACCESS

But when u copy and paste, Always remember to read and study the code and try to understand what it does, so u can lear.

Step One

2 Buttons (Open) (Save)
1 Open Dialog
1 Save Dialog
1 Image Holder

In the Uses Clause include "Jpeg"

Create this Procedure


Procedure SaveImagen(wimg:TImage;wfield:string);
 BlobStream: TStream;
 buf: tmemorystream;
  if wimg.Picture.Graphic <> nil then
      buf := tmemorystream.create();
    wimg.picture.graphic.savetostream(buf);, soFromBeginning);
//      buf.SaveToFile('U:\x.jpg');
    dataM.QryPersonnel.edit; //Your Data Set this is Mine
    TblobField( dataM.QryPersonnel.Fieldbyname('Picture')).LoadFromStream(buf);;;

Then on the Button Open


FileName: TFileName;
    if OpenD.Execute then

On the Save button



Good Luck

Josh 02-25-2010 01:38 PM

thanks this code works for me :)
i just have one more question, once i have saved a jpeg to my database it saves it as long binary data, i want to me able to display this in a new form -

once a button is clicked, a new form will appear showing the image that is stored in that record. how do i display this long binary data?

delphimpd 02-25-2010 06:06 PM

The same Code, but pointing to the new form and to the image Image.

Just put the new form in the uses clause, you can dynamically create the form or have it created automatically for you. But remember make sure if you dynamically create it, you must free it when you close it, if not memory will build up.

Josh 02-25-2010 07:40 PM

ive tried this, but all i am getting is a jpeg #42 error.... what do i do to solve this?

All times are GMT. The time now is 01:43 PM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.