delphi操作blobfield

delphi操作blobfield

procedure TForm2.Button1Click(Sender: TObject);
begin
  var Stream:TMemoryStream := TMemoryStream.Create;
  img1.Picture.Graphic.SaveToStream(Stream);
  dataset.Close;
  dataset.SQL.Clear;
  dataset.SQL.Text := 'insert into t1 (picture) values (:picture)';
  dataset.ParamByName('picture').LoadFromStream(Stream, ftBlob);
  dataset.ExecSQL;
  Stream.Free;
end;

procedure TForm2.Button2Click(Sender: TObject);
begin
 var Stream: TMemoryStream :=TMemoryStream.Create ;
 var jpg: TjpegImage := TjpegImage.Create ;
 TBlobField(dataset.FieldByName('picture')).SaveToStream(Stream);
 Stream.Position :=0;
 jpg.LoadFromStream(Stream);
 img1.Picture.Assign(Jpg);
 Stream.Free;
 Jpg.Free;
end;

  

  

posted @ 2022-07-05 09:09  delphi中间件  阅读(485)  评论(0编辑  收藏  举报