各位大虾 !!帮忙啊

解决方案 »

  1.   

    可以用TStringList过渡再导入文本文件
      

  2.   

    var
      slist:tstringlist;
    begin
      slist := tstringlist.create;
      query.first;
      for i := 0 query.recordcount -1 do 
      begin
        slist.add(query.fieldbyname('1').asstring +  query.fieldbyname('2').asstring + .. );
        query.next;
      end;
      slist.savetofile(filename)
      slist.free;
    end;
      

  3.   

    [此段代码来自网上]
    1、使用batchmove
    2、使用quickreport,在报表中加入TTextFileter控件,这样报表就支持
    另存为txt格式。
    3、ehlib在expert.csdn.net就有
    3、使用循环
    //把输出结果转换成文本文件
    function ChangetoText(TextForm:Tform;Query1:TQuery;title:string;summary:string): Boolean;
    var
      I: integer;
      FName,OutString: string;
      OutFile: TextFile;
      note: Tbook;
      savedialog1: Tsavedialog;
    begin
       //创建对话框的容器
     try
      savedialog1 := Tsavedialog.Create(TextForm);
      //Assign a filename to the variable
      savedialog1.Filter := 'Text files (*.txt)|*.TXT';
      if savedialog1.Execute then
        FName := savedialog1.FileName+'.txt';
      if FName <> '' then
        begin
          note := Query1.GetBook;
          Query1.DisableControls;  //Identify the filename and type as OutFile
         AssignFile(OutFile,fname);  //create and open a new file identify as OutFile
         Rewrite(OutFile);  //插入标题
         OutString := title+#13;
         Writeln(OutFile,OutString);
         OutString := '';  //Get text from the Query1
         for I:=0 to Query1.FieldCount-1 do
          begin
           if query1.Fields[i].Visible = True then
           begin
            OutString:=OutString+Query1.Fields[i].displaylabel;
            if I < Query1.FieldCount-1 then
              OutString := OutString + ','
            else outstring := Outstring;
           end;
          end;
        Writeln(OutFile,OutString);
        OutString := '';    While not Query1.EOF do
         begin
          for I:=0 to Query1.FieldCount-1 do
           begin
            if query1.Fields[i].Visible = True then
            begin
             OutString:=OutString+'"'+Query1.Fields[i].AsString+'"';
             if I < Query1.FieldCount-1 then
              OutString := OutString + ','
             else outstring := Outstring ;
            end;
           end;
      //Write out the text in OutString to file
          Writeln(OutFile,OutString);
          Query1.Next;
          OutString := '';
         end;   //插入总结
         Writeln(OutFile,summary);
      //Update and close the file
         CloseFile(OutFile);
         Query1.EnableControls;
         Query1.GotoBook(note);
         Query1.FreeBook(note);
         savedialog1.Destroy;
         result := True;
       end;
      except
       CloseFile(OutFile);
       Query1.EnableControls;
       Savedialog1.free;
       Showmessage('过程错误,请退出后重新运行!');
       Result := False;
      end;
    end;
      

  4.   

    我的第一想法也是xiaoxiao197821(你的笑对我很重要)的做法,虽然简单但是,执行效率可能会很低下,比方说:有10000条记录,20个属性。这可能会让人有点难以忍受。如果能想一个象把标准格式的文本文件倒入access一样快捷还挺有意义的。
      

  5.   

    var str1,str2,str3:string[30];
    table1.first;
    while not table1.eof do
    begin
    with table1 do
      str1:=fields[0].asstring;
      str2:=fields[1].asstring;
      str3:=fields[2].asstring;
      wreiteln(mytextfile,str1,str2,str2);
      next;
    end;
    end;
    效率是慢了一点,查过以前的资料,并没有更好的办法。
      

  6.   

    with adoquery1 do
    begin
        open;
        first;
        while not eot do
        begin
           for i:=i to fieldcount-1 do
           begin
                 s:=fields[i].astring;
                 write(F,s);
          end;
          write(F,#13);
        end;
        close;
    end;
      

  7.   

    这些代码里面没有涉及到dbgrid1啊 取得的数据为什么会是已经显示在dbgrid1里的数据,而不是整个数据库内的数据呢??var
      slist:tstringlist;
    begin
      slist := tstringlist.create;
      query.first;
      for i := 0 query.recordcount -1 do 
      begin
        slist.add(query.fieldbyname('1').asstring +  query.fieldbyname('2').asstring + .. );
        query.next;
      end;
      slist.savetofile(filename)
      slist.free;
    end;