[DUG] Images and MS SQL Server

Robert martin rob at chreos.co.nz
Mon Aug 18 16:25:27 NZST 2008


Might not help (not ADO componenets) but none the less.

//Loading image (file) into DB

                    FileStream 
:=TFileStream.Create(zClientsDM.OpenPictureDialog.FileName ,fmOpenRead 
or fmShareDenyNone);
                    try
                        with DataSet do begin
                            CreateBlobStream(FieldByName('Fieldname 
here'), bmReadWrite).CopyFrom(FileStream,0);
...
                        end;
                    finally
                        FileStream.Free;
                    end;


//Saving out of DB to file

                        Stream := 
DataSet.CreateBlobStream(DataSet.FieldByName('Field name here'), bmRead);
                        try
                            FileStream := TFileStream.Create(FileName, 
fmCreate);
                            try
                                FileStream.CopyFrom(Stream, 0);
                            finally
                                FileStream.Free;
                            end;
                        finally
                            Stream.Free;
                        end;

Hope thats of some use :)

Note : cut and paste but with some extras removed.

Rob

Dave O'Brien wrote:
> I've struck a complete blank on this.
> Can anyone show me some code to save and load images from SQL Server
> using TADOQuery?
> The methods I've come up with don't appear to work at all...
>
> -----Original Message-----
> From: delphi-bounces at delphi.org.nz [mailto:delphi-bounces at delphi.org.nz]
> On Behalf Of Neven MacEwan
> Sent: Friday, 15 August 2008 4:02 p.m.
> To: NZ Borland Developers Group - Delphi List
> Subject: Re: [DUG] Images and MS SQL Server
>
> Dave
>
> Hasn't Tblobfield got the same streaming functions IIRC
>   
>> I have worked out how to save an image into an Image field, but I'm 
>> having brain fade on how to retrieve the image... Using TADOQuery,
>>     
> D2005.
>   
>> Save:
>>
>> ...
>>
>> datamod.ADOU.SQL.Add(':Image)') ;
>>
>> ms := TMemoryStream.Create ;
>>
>> try
>>
>> Image.Picture.Bitmap.SaveToStream(ms);
>>
>> ms.seek(0,0) ;
>>
>> datamod.ADOU.Parameters.ParamByName('Image').LoadFromStream(ms, 
>> ftGraphic);
>>
>> finally
>>
>> ms.Free ;
>>
>> end ;
>>
>> datamod.ADOU.ExecSQL ;
>>
>> Anyone (I suppose everyone has) got a way to get the image back?
>>
>> Cheers,
>>
>> Dave.
>>
>>
>>     
> ------------------------------------------------------------------------
>   
>> _______________________________________________
>> NZ Borland Developers Group - Delphi mailing list
>> Post: delphi at delphi.org.nz
>> Admin: http://delphi.org.nz/mailman/listinfo/delphi
>> Unsubscribe: send an email to delphi-request at delphi.org.nz with
>>     
> Subject: unsubscribe
>
> _______________________________________________
> NZ Borland Developers Group - Delphi mailing list
> Post: delphi at delphi.org.nz
> Admin: http://delphi.org.nz/mailman/listinfo/delphi
> Unsubscribe: send an email to delphi-request at delphi.org.nz with Subject:
> unsubscribe
>
> No virus found in this incoming message.
> Checked by AVG - http://www.avg.com 
> Version: 8.0.138 / Virus Database: 270.6.4/1616 - Release Date:
> 16/08/2008 5:12 p.m.
>
> _______________________________________________
> NZ Borland Developers Group - Delphi mailing list
> Post: delphi at delphi.org.nz
> Admin: http://delphi.org.nz/mailman/listinfo/delphi
> Unsubscribe: send an email to delphi-request at delphi.org.nz with Subject: unsubscribe
>
>   


More information about the Delphi mailing list