向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控件顯示!
謝謝高手指教!