/bde要设置blobsize否则存进去,读不出来完整
数据库SQL Server,存放文件的字段类型Image
Create Table MyTable
(
FileName VarChar(20),
FileSource Image
)
存放文件到数据库
var FileName :String;
FileName := ExtractFileName(OpenDialog1.FileName);
with Query do
begin
Close;
Sql.Clear;
Sql.Add('INSERT INTO MyTable VALUES
FileName,:FileSource)');
ParamByName('FileName').AsString := FileName;
ParamByName('FileSource').LoadFromFile(OpenDialog1.FileName,ftBolob);
ExecSQL;
end;
从数据库中取出文件
var FileName :String;
begin
with Query do
begin
Close;
Sql.Clear;
Sql.Add('SELECT * FROM MyTable WHERE FileName = '?'');
Open; FileName := 'c:/'+FieldByName('FileName').AsString;
(FieldByName('FileSource') AS TBlobField).SaveToFile(FileName);
end;
end;