数据库中存取图片


//存数据

procedure
TForm1.Button1Click(Sender: TObject); var mm: TMemoryStream; begin mm := TMemoryStream.Create; image1.Picture.Graphic.SaveToStream(mm); sqlQuery1.SQL.Clear; SQLQuery1.SQL.Add('insert into datasnap_test (id, des, img) values (2, :des, :img)'); SQLquery1.ParamByName('des').Value := 'hello'; SQLQuery1.ParamByName('img').LoadFromStream(mm, ftBlob); SQLQuery1.ExecSQL(); mm.Free; end; //取数据
procedure
TForm1.Button2Click(Sender: TObject); var mm: TMemoryStream; JpegFile: TJpegImage; begin mm := TmemoryStream.Create; JpegFile := TJpegImage.Create; SQLQuery1.SQL.Clear; SQLQuery1.SQL.Add('select * from datasnap_test where id=2'); SQLQuery1.Open; TBlobField(SQLQuery1.FieldByName('img')).SaveToStream(mm); mm.Position := 0; jpegFile.LoadFromStream(mm); image2.Picture.Assign(JpegFile); mm.Free; end;

 

你可能感兴趣的:(数据库)