作为二进制数据来保存,都可以的。
Access里面为Ole字段类型。
function DBToDisk(Query_String, Column_Name, Target_Name: string): Boolean;
function DiskToDB(Query_String, Column_Name,Target_Name: string): Boolean;
function TForm1.DBToDisk(Query_String, Column_Name, Target_Name: string): Boolean;
var
l_FileStream: TFileStream;
begin
{从数据库中取出数据}
with Query1 do
begin
Close;
SQL.Text := Query_String;
Open;
end;
{将数据库中Image字段保存到硬盘下,存为文件}
l_FileStream := TFileStream.Create(Target_Name, fmOpenWrite or fmCreate);
l_FileStream.Position := 0;
TBlobField(Query1.FieldByName(Column_Name)).SaveToStream(l_FileStream);
l_FileStream.Free;
Query1.Close;
Result := True; //所有任务彻底完成,Function返回True
end;
function TForm1.DiskToDB(Query_String, Column_Name,Target_Name: string): Boolean;
var
l_FileStream: TFileStream;
begin
with Query1 do
begin
Close;
SQL.Clear;
SQL.Text := Query_String;
Open;
end;
Query1.Edit;
l_FileStream := TFileStream.Create(Target_Name, fmShareDenyNone);
l_FileStream.Position := 0;
TBlobField(Query1.FieldByName(Column_Name)).loadfromStream(l_FileStream);
Query1.Post;
l_FileStream.Free;
Result := True; //一切任务完成,返回True
end;