BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Saving JPEG images to images field in SQL2000 with ADODataSe

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (ADO)
View previous topic :: View next topic  
Author Message
Wira
Guest





PostPosted: Thu Jun 15, 2006 8:10 am    Post subject: Saving JPEG images to images field in SQL2000 with ADODataSe Reply with quote



I'm Using D5 and SQL2000 for database.
One of my tables in SQL2000 have an image field type for saving picture ,
the problem is when I want to save JPEG images into my table always appear
error message "Bitmap image is not valid".


procedure SavePicture ;
var FStream : TMemoryStream ;
begin
with tblPicture do begin //tblPicture is ADODataSet Component
try
Insert ;
FStream := TMemoryStream.Create ;
FStream.LoadFromFile('C:\PictureFiles\Image01.JPG') ;
TBlobField(FieldByName('im_pic_thumbnail')).LoadFromStream(FStream)
;
Post ;
finally
FStream.Free
end;
end;
end;



Thanks

Wira
Back to top
Wira
Guest





PostPosted: Thu Jun 15, 2006 1:00 pm    Post subject: Re: Saving JPEG images to images field in SQL2000 with ADODa Reply with quote



Hi Martin,

It doesn't work. According to help file, I read that SaveToStream function
is saving contents of the Blob to a stream variabel.

Thanks
Wira



"Martin Cremer" <Martin..Cremer (AT) web (DOT) de> wrote in message
news:44911779$1 (AT) newsgroups (DOT) borland.com...
Quote:
How abaout SaveToStream(FStream)

Cheers

Martin Cremer



"Wira" <wira (AT) margonopaper (DOT) com> schrieb im Newsbeitrag
news:4490f687 (AT) newsgroups (DOT) borland.com...
I'm Using D5 and SQL2000 for database.
One of my tables in SQL2000 have an image field type for saving picture
,
the problem is when I want to save JPEG images into my table always
appear
error message "Bitmap image is not valid".


procedure SavePicture ;
var FStream : TMemoryStream ;
begin
with tblPicture do begin //tblPicture is ADODataSet Component
try
Insert ;
FStream := TMemoryStream.Create ;
FStream.LoadFromFile('C:\PictureFiles\Image01.JPG') ;

TBlobField(FieldByName('im_pic_thumbnail')).LoadFromStream(FStream)
;
Post ;
finally
FStream.Free
end;
end;
end;



Thanks

Wira



Back to top
Martin Cremer
Guest





PostPosted: Thu Jun 15, 2006 1:16 pm    Post subject: Re: Saving JPEG images to images field in SQL2000 with ADODa Reply with quote



How abaout SaveToStream(FStream)

Cheers

Martin Cremer



"Wira" <wira (AT) margonopaper (DOT) com> schrieb im Newsbeitrag
news:4490f687 (AT) newsgroups (DOT) borland.com...
Quote:
I'm Using D5 and SQL2000 for database.
One of my tables in SQL2000 have an image field type for saving picture ,
the problem is when I want to save JPEG images into my table always appear
error message "Bitmap image is not valid".


procedure SavePicture ;
var FStream : TMemoryStream ;
begin
with tblPicture do begin //tblPicture is ADODataSet Component
try
Insert ;
FStream := TMemoryStream.Create ;
FStream.LoadFromFile('C:\PictureFiles\Image01.JPG') ;

TBlobField(FieldByName('im_pic_thumbnail')).LoadFromStream(FStream)
;
Post ;
finally
FStream.Free
end;
end;
end;



Thanks

Wira

Back to top
treok
Guest





PostPosted: Thu Jun 15, 2006 6:03 pm    Post subject: Re: Saving JPEG images to images field in SQL2000 with ADODa Reply with quote

This code works for me:

procedure SaveJpegToTable(Table: TADODataset; PicField:TBlobField;
sPicPath: string);
var
fS : TFileStream;
begin
fs:=TFileStream.Create(sPicPath, fmOpenRead);
try
Table.Edit;
PicField.LoadFromStream(fs);
Table.Post;
finally
fs.Free;
end;
end;



--- posted by geoForum on http://delphi.newswhat.com
Back to top
Brian Bushay TeamB
Guest





PostPosted: Fri Jun 16, 2006 6:10 am    Post subject: Re: Saving JPEG images to images field in SQL2000 with ADODa Reply with quote

Quote:
I'm Using D5 and SQL2000 for database.
One of my tables in SQL2000 have an image field type for saving picture ,
the problem is when I want to save JPEG images into my table always appear
error message "Bitmap image is not valid".

With that error my guess is that you are trying to display the bitmap using a
TdbImage field. A tdbImage field can only display a bitmap
--
Brian Bushay (TeamB)
Bbushay (AT) NMPLS (DOT) com
Back to top
Wira
Guest





PostPosted: Fri Jun 16, 2006 8:11 am    Post subject: Re: Saving JPEG images to images field in SQL2000 with ADODa Reply with quote

Yes, that's right ,
I used TDBImage component to display the picture from image field type in
SQL 2000.
If a TDBImage component can not display a JPEG , should I use TImage
component as a subtitute of TDBImage?
And how to display the image from image field type in SQL 2000 if I use
TImage?

Thanks

Wira


"Brian Bushay TeamB" <BBushay (AT) Nmpls (DOT) com> wrote in message
news:h11492969jvmm9e03drm7no9cppt9gfgeo (AT) 4ax (DOT) com...
Quote:

I'm Using D5 and SQL2000 for database.
One of my tables in SQL2000 have an image field type for saving picture ,
the problem is when I want to save JPEG images into my table always
appear
error message "Bitmap image is not valid".

With that error my guess is that you are trying to display the bitmap
using a
TdbImage field. A tdbImage field can only display a bitmap
--
Brian Bushay (TeamB)
Bbushay (AT) NMPLS (DOT) com
Back to top
Dennis Passmore
Guest





PostPosted: Fri Jun 16, 2006 3:36 pm    Post subject: Re: Saving JPEG images to images field in SQL2000 with ADODa Reply with quote

The following code works nicely.

procedure TForm1.btnSaveSQLClick(Sender: TObject);
var
Stream: TADOBlobStream;
begin
ADOConnection1.Execute('delete from dbo.Categories where ' +
'(CategoryName = ''Test'')');
ADODataset1.active := true;
ADODataset1.Insert;
ADODataSet1CategoryName.AsString := 'Test';
ADODataSet1Description.asstring := lowercase(edit1.text);
Stream := TADOBlobStream.Create(ADODataSet1Picture, bmWrite);
if Image1.Picture.Graphic is TJPEGImage then
TJPEGImage(Image1.Picture.Graphic).SaveToStream(Stream)
else
Image1.Picture.Bitmap.SaveToStream(Stream);
Stream.Free;
ADODataset1.Post;
ADODataset1.active := false;
end;

procedure TForm1.btnLoadSQLClick(Sender: TObject);
var
Stream : TADOBlobStream;
fJPEGImage: TJPEGImage;
begin
ADODataset1.active := true;
if ADODataset1.Locate('CategoryName','Test',[]) then
begin
edit2.text := 'new_'+ADODataSet1Description.asstring;
Stream := TADOBlobStream.Create(ADODataSet1Picture, bmRead);
Stream.Position := 0;
if (pos('.jpg',ADODataSet1Description.asstring)>0) then
begin
fJPEGImage := TJPEGImage.create;
fJPEGImage.LoadFromStream(Stream);
Image1.Picture.Assign(fJPEGImage);
fJPEGImage.Free;
end
else
Image1.Picture.Bitmap.LoadFromStream(Stream);
Stream.Free;
end;
ADODataset1.active := false;
end;

Dennis Passmore



"If you cannot conceive the idea you
will never achieve the desired results"
Back to top
Brian Bushay TeamB
Guest





PostPosted: Mon Jun 19, 2006 6:19 am    Post subject: Re: Saving JPEG images to images field in SQL2000 with ADODa Reply with quote

Quote:
Yes, that's right ,
I used TDBImage component to display the picture from image field type in
SQL 2000.
If a TDBImage component can not display a JPEG , should I use TImage
component as a subtitute of TDBImage?
Yes
And how to display the image from image field type in SQL 2000 if I use
TImage?
You will have to write code to load the image from the record,

See code from Dennis

--
Brian Bushay (TeamB)
Bbushay (AT) NMPLS (DOT) com
Back to top
Wira
Guest





PostPosted: Mon Jun 19, 2006 3:17 pm    Post subject: Re: Saving JPEG images to images field in SQL2000 with ADODa Reply with quote

I tried the codes , the result is working good.

Thanks for all.

Wira


"Brian Bushay TeamB" <BBushay (AT) Nmpls (DOT) com> wrote in message
news:5mtb92pphfoch8vu0cp97gg5ddh24epd46 (AT) 4ax (DOT) com...
Quote:


Yes, that's right ,
I used TDBImage component to display the picture from image field type in
SQL 2000.
If a TDBImage component can not display a JPEG , should I use TImage
component as a subtitute of TDBImage?
Yes
And how to display the image from image field type in SQL 2000 if I use
TImage?
You will have to write code to load the image from the record,
See code from Dennis

--
Brian Bushay (TeamB)
Bbushay (AT) NMPLS (DOT) com
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (ADO) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.