用一个dbgrid控件和ADOTable显示sql server里的数据库表记录,然后对其进行修改、删
除和添加记录等功能,本来是很容易的事情,但是表里有图像,也就是image型。这样就麻
烦了怎么在dbgrid中显示图像呢?如果能显示图像的话,怎么实现把图像从磁盘里放到dbgrid中,再存储到数据库表中去呢
?好生麻烦的事情阿,各位有遇到过吗?该如何解决呢?
除和添加记录等功能,本来是很容易的事情,但是表里有图像,也就是image型。这样就麻
烦了怎么在dbgrid中显示图像呢?如果能显示图像的话,怎么实现把图像从磁盘里放到dbgrid中,再存储到数据库表中去呢
?好生麻烦的事情阿,各位有遇到过吗?该如何解决呢?
代码例子如下:
DBImage1.picture.LoadFromFile(OpenPictureDialog1.FileName);
if DBImage1.picture.Graphic <> nil then {//避免image1中无图像保存出错}
begin //begin6
strm := tmemorystream.Create;
try //try1
DBImage1.picture.Graphic.SaveToStream(strm);
ADOTable1.Edit;
strm.Position := 0;
TBlobField(ADOTable1.fieldbyname('identification')).LoadFromStream(strm);
ADOTable1.post;
finally
strm.Free;
end; //end try1
end; //end begin6