Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 02-23-2010, 05:09 PM
Josh Josh is offline
Junior Member
 
Join Date: Feb 2010
Posts: 9
Default insert a image into a microsoft access database

hi,

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

begin
opendialog1.Execute;
with adotable1 do
begin
Edit;
(fieldbyName('Picture') as Tblobfield).loadfromFile(opendialog1.filename);
Post;
end;

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.
Reply With Quote
  #2  
Old 02-24-2010, 01:21 PM
MrBaseball34 MrBaseball34 is offline
Senior Member
 
Join Date: Jan 2001
Posts: 7,260
Default

What is the Access FieldType for the Picture field?
__________________
MrBaseball34

Hook 'em Horns
2005 College Football National Champions
2005 College Baseball National Champions
Reply With Quote
  #3  
Old 02-24-2010, 08:06 PM
Josh Josh is offline
Junior Member
 
Join Date: Feb 2010
Posts: 9
Default

i set it as an OLE image.
Reply With Quote
  #4  
Old 02-24-2010, 09:16 PM
MrBaseball34 MrBaseball34 is offline
Senior Member
 
Join Date: Jan 2001
Posts: 7,260
Default

Have you seen this article?
http://delphi.about.com/od/database/l/aa030601a.htm
__________________
MrBaseball34

Hook 'em Horns
2005 College Football National Champions
2005 College Baseball National Champions
Reply With Quote
  #5  
Old 02-24-2010, 09:47 PM
Josh Josh is offline
Junior Member
 
Join Date: Feb 2010
Posts: 9
Default

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.
Reply With Quote
  #6  
Old 02-25-2010, 01:36 AM
MrBaseball34 MrBaseball34 is offline
Senior Member
 
Join Date: Jan 2001
Posts: 7,260
Default

Let me check out some other things.
__________________
MrBaseball34

Hook 'em Horns
2005 College Football National Champions
2005 College Baseball National Champions
Reply With Quote
  #7  
Old 02-25-2010, 05:58 AM
delphimpd delphimpd is offline
Senior Member
 
Join Date: Oct 2006
Posts: 701
Default

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

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

Then on the Button Open

Code:
Var
FileName: TFileName;
  begin
    if OpenD.Execute then
     Begin
      FileName:=opend.filename;
      ProfilePicture.Picture.LoadFromFile(FileName);
     RestrictedImage.Picture.LoadFromFile(FileName);
end;

On the Save button

Code:
 SaveImagen(ProfilePicture,'Picture');
  SaveImagen(RestrictedImage,'Picture');

Good Luck
Reply With Quote
  #8  
Old 02-25-2010, 01:38 PM
Josh Josh is offline
Junior Member
 
Join Date: Feb 2010
Posts: 9
Default

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?
Reply With Quote
  #9  
Old 02-25-2010, 06:06 PM
delphimpd delphimpd is offline
Senior Member
 
Join Date: Oct 2006
Posts: 701
Default

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.
Reply With Quote
  #10  
Old 02-25-2010, 07:40 PM
Josh Josh is offline
Junior Member
 
Join Date: Feb 2010
Posts: 9
Default

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

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 10:03 AM.


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