谢谢!

解决方案 »

  1.   

    sl:=TStringList.Create;
    try
      sl.LoadFromFile(Hanzi.txt');
      adotable1.open;
      for i:=0 to sl.Count-1 do
      begin    
        adotable1.append;
        adotable1.fieldbyname(aaa):=sl.strings[i];
        adotable1.post;
      end;
    finally
      adotable1.close;
      sl.Free;
    end; 
      

  2.   

    1。txt文件必须是有一定格式的,比如用#分割各个字段值
    2。自己读取后,用servers控件组的TexcelApplication写道特定的文件里:)
      

  3.   

    adotable1.field(i).value:=sl.strings[i];
      

  4.   

    cg1120说的方法中由于你存的时候将一条记录存成一行,这样stringlist读进来后
    stringlist.string[i]一个字符串是一行文本,可以按字符读,不过你要规定好两个字段之间有什么在文本中断开,下面的程序是用#9(tab)断开的;
    procedure txzdmfrm.TxtToDB(SourceTable:TAdotable;Txtname:TFileName); //文本入数据库
    var
      F1:Textfile;
      i:integer;
      TmpStr:string;
      ch:char;
    begin
      try
        AssignFile(F1,txtname);
        reset(f1);
        read(f1,ch);
        while ch<>#26 do begin
          if not SourceTable.Active then SourceTable.Open;
          sourceTable.Append;
          for i:=0 to SourceTable.FieldCount-1 do begin
            TmpStr:='';
            while (ch<>#9) do
              begin     //#9 is tab
                if ch<>#13 then
                   begin     //#13 is enter
                    if ch<>#26 then
                       begin    //#26 is line end
                        Tmpstr:=TmpStr+ch;
                        read(F1,ch);
                       end
                     else
                       begin
                         closefile(f1);
                         //showmessage('ok');
                         exit;
                       end;
                  end
                else
                  read(f1,ch);
             end;
            read(F1,ch);
            SourceTable.Fields[i].AsString:=trim(TmpStr);
          end;//end of (for i:=0 to SourceTable.FieldCount-1 do)
        end;//end of (if not eof(f1) then
      except
        closefile(f1);
        MessageDlg( '接收数据失败!',mtError,[mbOk],0);
      end;
    end;
      

  5.   

    定义一个记录,它表示了.txt文本的结构,然后再用这个记录去读取文本。我以前做过,不过,现在要忙了,中午再给你代码吧!
      

  6.   

    各位,我的代码如下:
    procedure TForm1.Button3Click(Sender: TObject);
    var sl:tstringlist;
        i:integer;
    begin
      sl:=TStringList.Create;
      sl.LoadFromFile(opendialog1.FileName);
      adotab.open;
      try
        for i:=0 to sl.Count-1 do  
        begin
             with adotab do
             begin
               append;
               sl.Delimiter:=',';
               sl.DelimitedText:=memo1.Lines.Text;
               adotab.Fields[i].AsString:=sl.Strings[i];
               post;
             end;
        end;  
      finally
        adotab.close;
        sl.Free;
      end;
    end;
    比如我的记录应该是 
                 字段1  字段2  字段3  字段4  字段5  字段6
    第1条记录      1      2      3      4      5     6
    当程序运行完后,存到表中的数据却是这样的,
                  字段1  字段2  字段3  字段4  字段5  字段6
    第1条记录      1      
    第1条记录              2     
    第1条记录                     3     
    第1条记录                            4   
    第1条记录                                   5   
    第1条记录                                         6该怎么办啊?