向SQL Server插入记录相信大家都会做,但是如果表中带有Image字段就不好弄了,这里有一个例子,非常安全,同时也向大家展示动态生成控件的技巧!
在SQL Server中建立TEST表,两个字段,id varchar(10),photo image(16);

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
openpicturedialog1.execute;
image1.picture.loadfromfile(openpicturedialog1.filename);
end;

procedure TForm1.BitBtn2Click(Sender: TObject);
var
            graphic1:Timage;
begin
graphic1:=Timage.Create(self);
graphic1.picture.loadfromfile(openpicturedialog1.filename);
table1.Open;
table1.insert;
table1.fieldbyname(’id’).asstring:=’121’;
table1.fields[1].assign(graphic1.Picture);
table1.post;
table1.close;
graphic1.free;
end;


显示可用:
DBIMAGE控件显示!
谢谢高手指教!