字段该用什么类型?怎么保存和读取?

解决方案 »

  1.   

    procedure FileToDB(ADOQuery:TADOQuery;FileName,FieldName:String);
    var
     aFile:TADOBlobStream;
    begin
     ADOQuery.Edit;
     aFile:=TADOBlobStream.Create((ADOQuery.Fieldbyname(FieldName) as TBlobField),bmWrite);
     if FileName = '' then
       aFile.Truncate
     else
       aFile.LoadFromFile(filename);
     aFile.free;
     ADOQuery.Post; Application.MessageBox(pchar('保存成功'),pchar(Application.title),mb_ok+mb_iconinformation);
    end;
    procedure TForm1.Button1Click(Sender: TObject);var aa:string;
    begin
      if OpenDialog1.Execute then
      aa:=OpenDialog1.FileName;
      FileToDb(ADOQuery1,aa,'照片');end;字段用:OLE 对象
      

  2.   

    //从数据库取得文件
    function FileFromDB(FieldName,outfile:string;ADOQuery:TADOQuery):boolean;
    var
     AFile:TADOBlobStream;
     fileName:string;
     i:integer;
    begin //将QUERY控件ADOQuery中字段fieldName的内容作为BOLB类型字段保存到文件SavePath+preFileName+COUNT中去
     result:=false;
     with ADOQuery do
     begin
       if not eof then
       begin
         if (Fieldbyname(FieldName).isnull)or
                   (not (Fieldbyname(FieldName) is TBlobField)) then
          //空内容或非二进制内容直接跳过
                   exit;     AFile:=TADOBlobStream.Create((Fieldbyname(FieldName) as TBlobField),bmRead);
         AFile.SaveToFile(outfile);
         result:=true;
         AFile.free;
       end;
     end;
    end; //忘了说:代码是人家高手写的,我是COPY来的