大家都知道TClientDataSet可以将内容输出到一个文件,现在我想将一个图片(或者其他文件)存入TClientDataSet的一个blob字段(或者其他类型,比如Graphic,只要能达到目的),之后将当前TClientDataSet的内容输出到一个文件中,并能读回TClientDataSet中,怎么做?可以额外给分!

解决方案 »

  1.   

    //读入文件
    TBlobField(ClientDataSet1.FieldByName('fieldname')).LoadFromFile('filename');//保存到文件
    TBlobField(ClientDataSet1.FieldByName('fieldname')).SaveToFile('filename');
      

  2.   

    但是ClientDataSet1.SaveToFile失败,导不出文件,没有提示,为什么会这样?
      

  3.   

    我想将ClientDataSet1内的数据(包括已经存入的图片)全部导出到一个文件内,比如:test.怎么办啊?
      

  4.   

    转载:
    //文件存储到数据库
    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;
    //从数据库取得文件
    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; 
      

  5.   

    将有关TADOQuery,改成TClientDataSet
      

  6.   

    TJPEGIMAGE不是也有SAVETOFILE和LOADFROMFILE方法吗?