Page 1 of 1

insert an image into a database and also how to retrieve it

PostPosted: September 18th, 2009, 10:29 am
by claudiu_k
](*,)

Hi!

Please help me! I need to know how to insert an image into a database and also how to retrieve it back?
So, I have a table (PictureTable) whit one column named (Picture) and I need to insert, update and to access images.
On the program I have a table, a picture which I change how I wont and a button. When I click the button I need to insert the new image in table and when I click the table I need to get the image in the image component from the activated table row.

Thanks you!

Re: insert an image into a database and also how to retrieve it

PostPosted: September 18th, 2009, 1:37 pm
by Kambiz

Re: insert an image into a database and also how to retrieve it

PostPosted: September 18th, 2009, 5:50 pm
by geowink
I suggest putting the name of the graphic in the database. I put the base location in an INI file entry so that makes it changeable. That is, c:\MyPics\ goes in the INI and PictureName goes in the field. Then get the total location: GraphPath := IniLoc + PictureName + '.jpg';

Then...

if FileExists(GraphicPath) then
begin
Stream := TMemoryStream.Create;
Image := TJPEGImage.Create;
try
Image.LoadFromFile(GraphicPath);
Image.SaveToStream(Stream);
Stream.Position := 0;

Just a possibility.

George