有什么思路和技巧?
只能历遍每条记录的每个字段读出来后写到文件里面?还是有其他便捷一点的方法?

解决方案 »

  1.   

    查查是否有savetofile的函数,理论上应该有的
      

  2.   

    SaveToFile不能直接保存为文本文件。
      

  3.   

    SaveToFile不行,只能保存pfADTG/pfXML两种格式。
    不知道有没有类似功能的控件?
      

  4.   

    用游标declare @m1
    declare @m2
        BEGIN 
    declare cur cursor
        for  select 
    open cur
    fetch cur into @m1,@m2while (@@sqlstatus=2)
    begin
        close cur
        return
    endselect @stra=''
    while (@@sqlstatus=0)
       
    begin
     select .....(处理记录数据)
     fetch cur into @m1,@m2
    end
    close cur
      

  5.   

    //把数据库集导出文本
    procedure ExportDBTxt(AQ:TADOQuery;FileName:string);
    var
       DesTable: TkbMMemTable;
       CSVFormat:TkbmCSVStreamFormat;
        OpenDialog: TOpenDialog;
        i,j: integer;
        TempFieldDef: TFieldDef;
    begin
      if not AQ.Active then exit;
      try
        Screen.Cursor := crHourGlass;
        //创建格式
        CSVFormat:=TkbmCSVStreamFormat.Create(Application);
        CSVFormat.CSVQuote :=Quote;
        CSVFormat.CSVFieldDelimiter :=FieldDelimiter;
        CSVFormat.CSVRecordDelimiter :=RecordDelimiter;
        DesTable := TkbmMemTable.Create(Application);
        DesTable.DefaultFormat :=CSVFormat;
        DesTable.FormFormat :=CSVFOrmat;
        DesTable.PersistentFormat :=CSVFormat;
        For i := 0 to AQ.FieldDefList.Count - 1 do
        if AQ.FindField(AQ.FieldDefList.FieldDefs[i].Name)<>nil then
        begin        TempFieldDef := DesTable.FieldDefs.AddFieldDef;
            TempfieldDef.Assign(AQ.FieldDefList.FieldDefs[i]);
        end;
        DesTable.Open;    AQ.First;
        while not AQ.Eof do
        begin
          DesTable.Append;
          j := -1;
          For i := 0 to DesTable.FieldCount - 1 do
          begin
             //if Source.Fields[i].FieldKind = fkData then
             begin
               j := j + 1;
               DesTable.Fields[i].Value := AQ.FieldByName(DesTable.Fields[i].FieldName).Value;
             end;
          end;
          DesTable.Post;
          AQ.Next;
        end;
           DesTable.SaveToFile(FileName);
        DesTable.Close;
        DesTable.Free ;
        CSVFormat.Free ;
        Screen.Cursor := crDefault;
        MessageBox(0,'数据已经被成功导出!','导出',MB_OK + MB_ICONINFORMATION + MB_APPLMODAL);
      except
        DesTable.Free ;
        CSVFormat.Free ;
        Screen.Cursor := crDefault;
        MessageBox(0,'数据导出失败!','导出',MB_OK + MB_ICONWARNING + MB_APPLMODAL);
      end
    end;