var FileName :String;FileName := ExtractFileName(OpenDialog1.FileName);with Query dobegin 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;
Query1.Close;
Query1.SQl.Clear;
Query1.Add('Insert Into A Values B) '); //B为Blob字段
Query1.ParamByName('aaa').LoadFromFile('路径');
Query1.Execsql;
//-----------------------------
var a : TMemoryStream;
a:=TMemoryStream.Create;
image1.Picture.Bitmap.SaveToStream(a);
TBlobField(query1.FieldByName('aaa')).LoadFromStream(a);
query1.Post;