流的方式保存图片导数据库

procedure SavePictureToSQL();
var
msmem: TmemoryStream;
jpg: TJpegImage;
FName: string;
SqlStr: string;
begin
//保存
try
msmem := TmemoryStream.Create;
Jpg := TjpegImage.Create;
//jpg.Assign(form2.Image1.Picture.Graphic);
jpg.Assign(MyChart1.Chart);
jpg.SaveToStream(msmem); // 1
msmem.Position := 0;
SqlStr := 'Select * From Result_PIC where ProjectName=' + QuotedStr(PrjInFo);
UnitFunction.ADOQRun(ADOQuery1, SqlStr);
if ADOQuery1.Eof = False then
begin
ADOQuery1.Edit;
TBlobField(ADOQuery1.FieldByName(FName)).LoadFromStream(msmem);
ADOQuery1.Post;
end
else
begin
ADOQuery1.Insert;
ADOQuery1.FieldByName('ProjectName').Value := PrjInFo;
TBlobField(ADOQuery1.FieldByName(FName)).LoadFromStream(msmem);
ADOQuery1.Post;
end;
Msmem.Free;
jpg.Free;
except end;
end;

posted @ 2020-03-26 09:43  南国之恋  阅读(186)  评论(0编辑  收藏  举报