Saving Image/Picture to Database using ADO



Can someone help with loading a JPG image into an SQL database using Delphi
7.
All the links I find don't quite do it for me.

The problem is simple.
Load a JPG file stored on my Hard Drive into an MSSQL database field.

I have tried the following but I get a 'Bitmap Image is Invalid' Error
message.

procedure TfrmCompany.SaveJpegToTable(Table: TADOQuery; PicField:TBlobField;
sPicPath: string);
{
Usage:

SPicFileName := 'C:\!gajba\cdcovers\cdcover1.jpg';
SaveJpegToTable(ADOTable1, ADOTable1Picture, SPicFileName);
}
var
fS : TFileStream;
begin
// fs:=TFileStream.Create(sPicPath, fmOpenRead);
fs:=TFileStream.Create(PicField, fmOpenRead);
try
Table.Edit;
// JpegStartsInfs(PicField, fs);
PicField.LoadFromStream(fs);
Table.Post;
finally
fs.Free;
end;
end;

Any help would be appreciated.

Thanks,
Leonard


.


Quantcast