怎样把图片存到数据库的graphic字段类型中去
编号:QA003925
建立日期: 2001年2月26日 最后修改日期:2001年3月15日
所属类别:
wangfei:
操作系统: windows98
编程工具: delphi
问题: 怎样把图片存到数据库的graphic字段类型中去?所用的数据库是borland paradox.
最好有举例说明。
谢谢!
水平: 刚入门
回答:
定义一个Graphic类型的变量且该变量要用Assing()函数传递到相应数据库中保存。如:
procedureTForm1.btnSaveClick(sender:TObject);
var Graphic1: TGraphic;
begin
Graphic1 := TGraphic.Create;
Graphic1.LoadFromFile(OpenDialog1.Filename);
Table1.insert;
... 插入其他字段
Table1.Fields[4].Assign(Graphic1);
Table1.Post;
Graphic1.Free;
end;
也可以这样将字段的内容保存:
Table1.Open;
Table1.Edit;
Table1.Fields[4].SaveToFile('C:\my.bmp');
Table1.Close;
或这样读文件:
Table1.Open;
Table1.Edit;
Table1.Fields[4].LoadFromFile('c:\my.bmp');
Table1.Close;
旺仔的意见:
例如:存储图片的字段名是Picture,在窗体中放TQuery数据访问部件。
示范代码如下:
with Query1 do
begin
Close;
Sql.Clear;
Sql.Add('Insert into TableName(Picture)');
Sql.Add('Values(:P_Picture)');
ParamByName('P_Picture').LoadFromFile('FilePath');
ExecSql;
Close;
end;
end;
此问题由李海回答。
| |
|
|
| |
|
|