| View previous topic :: View next topic |
| Author |
Message |
Wira Guest
|
Posted: Thu Jun 15, 2006 8:10 am Post subject: Saving JPEG images to images field in SQL2000 with ADODataSe |
|
|
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
|
Posted: Thu Jun 15, 2006 1:00 pm Post subject: Re: Saving JPEG images to images field in SQL2000 with ADODa |
|
|
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
|
Posted: Thu Jun 15, 2006 1:16 pm Post subject: Re: Saving JPEG images to images field in SQL2000 with ADODa |
|
|
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
|
Posted: Thu Jun 15, 2006 6:03 pm Post subject: Re: Saving JPEG images to images field in SQL2000 with ADODa |
|
|
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
|
Posted: Fri Jun 16, 2006 6:10 am Post subject: Re: Saving JPEG images to images field in SQL2000 with ADODa |
|
|
| 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
|
Posted: Fri Jun 16, 2006 8:11 am Post subject: Re: Saving JPEG images to images field in SQL2000 with ADODa |
|
|
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
|
Posted: Fri Jun 16, 2006 3:36 pm Post subject: Re: Saving JPEG images to images field in SQL2000 with ADODa |
|
|
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
|
Posted: Mon Jun 19, 2006 6:19 am Post subject: Re: Saving JPEG images to images field in SQL2000 with ADODa |
|
|
| 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
|
Posted: Mon Jun 19, 2006 3:17 pm Post subject: Re: Saving JPEG images to images field in SQL2000 with ADODa |
|
|
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 |
|
 |
|