alim_maze
asked on
Upload/Download picture from/to SQL server DB
Can you please give a code to Upload and download pictures from any type (.bmp,Jpg ..) to MS-SQL Database and then retrieve it back ?
I made simple code to upload -attached - but this is only useful for bitmap
the answer should include the following parts:
1)- Upload Delphi Code on button event + MS-SQL stored procedure
2)- Download Delphi Code on dbgrid.cellclick + MS-SQL procedure
regards,
Alim
I made simple code to upload -attached - but this is only useful for bitmap
the answer should include the following parts:
1)- Upload Delphi Code on button event + MS-SQL stored procedure
2)- Download Delphi Code on dbgrid.cellclick + MS-SQL procedure
regards,
Alim
procedure TForm2.Button1Click(Sender: TObject);
begin
sp.close;
sp.ProcedureName:='upload_img';
sp.Parameters.Refresh;
sp.Parameters.ParamByName('@img').LoadFromFile(
OpenPictureDialog1.FileName,ftGraphic);
sp.ExecProc;
end;
Stored Procedure :
CREATE PROCEDURE [dbo].[upload_img]
@img image
AS
BEGIN
insert into images (img) values (@img)
END
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I have never seen it done through parameters before. I tend to set up a TADOQuery, get my record results, typecast a BLOB or IMAGE type field as a TBlobField in Delphi, then use the LoadFromFile or SaveToFile methods.
ASKER
dear developmentguru,
would you write some code explaining your ideas ..
all I need is your best way to upload and download pictures (of several types) to and from SQL database written with some sample code.
would you write some code explaining your ideas ..
all I need is your best way to upload and download pictures (of several types) to and from SQL database written with some sample code.
ASKER
I'll repeat the requirements of this question:
1)- simple Delphi code (procedure/function) to upload a picture (gif,jpg,bmp ..) to MsSQL DB using ADO (query/Stored procedure .. whatever)
2)- simple Delphi code (procedure/function) to download a picture (gif,bmp,jpg ..) from SQL DB to image1 VCL on form of my application.
I raised the point of this question from 125 to 250,
now please would some body collect these easy points ?!
regards,
Alim
1)- simple Delphi code (procedure/function) to upload a picture (gif,jpg,bmp ..) to MsSQL DB using ADO (query/Stored procedure .. whatever)
2)- simple Delphi code (procedure/function) to download a picture (gif,bmp,jpg ..) from SQL DB to image1 VCL on form of my application.
I raised the point of this question from 125 to 250,
now please would some body collect these easy points ?!
regards,
Alim
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I now have great result uploading/downloading , the only thing I need now is: how to load the picture from DB to image VCL directly (no files):
Proc
var
img:TBlobField;
begin
img:=TBlobField(ADOTable1. FieldByNam e('img'));
img.SaveToFile(ChangeFileE xt(paramst r(0),'.jpg '));
// image1.picture. ???
end;
Proc
var
img:TBlobField;
begin
img:=TBlobField(ADOTable1.
img.SaveToFile(ChangeFileE
// image1.picture. ???
end;
ASKER
I saw your line Image1.Picture.Assign(TGIF Image(fGIF s[I]));
but I need something more easier to load from Tadoquery, for example:
var
img:TBlobField;
begin
img:=TBlobField(ADOTable1. FieldByNam e('img'));
image1.picture ...
but I need something more easier to load from Tadoquery, for example:
var
img:TBlobField;
begin
img:=TBlobField(ADOTable1.
image1.picture ...
You will need to:
1) save the blob field to an in memory stream
2) Create a TGIFImage
3) Load the GIF Image from the in memory stream
4) Do the Image1.Picture.Assign to the TGIFImage
You can wrap all of that in a method or procedure if you want, but it is all necessary.
1) save the blob field to an in memory stream
2) Create a TGIFImage
3) Load the GIF Image from the in memory stream
4) Do the Image1.Picture.Assign to the TGIFImage
You can wrap all of that in a method or procedure if you want, but it is all necessary.
ASKER
thank you ..
my best and fastest way to solve this case (with the help of DevExpress cxImage) is as follows:
my best and fastest way to solve this case (with the help of DevExpress cxImage) is as follows:
// 1)- Upload picture to DB:
sp.close;//sp: is TADOStoredProcedure
sp.ProcedureName:='upload_img';
sp.Parameters.Refresh;
sp.Parameters.ParamByName('@img').LoadFromFile(
sp.Parameters.ParamByName('@ext').value:=(
extractfileext(
OpenPictureDialog1.FileName,ftGraphic));
sp.ExecProc;
(or I can use AdoQuery)
// 2)- Download picture from DB:
var
img:TBlobField;
fname:string;
begin
img:=TBlobField(ADOTable1.FieldByName('img'));
fname:=ChangeFileExt(paramstr(0),ADOTable1.FieldByName('ext'));
img.SaveToFile(fname);
cxImage1.Picture.LoadFromFile(fname);
end;