我想将access数据库数据导出为文本格式。请问用delphi如何实现?

解决方案 »

  1.   

    很容易。用ADOQUERY 取出ACCESS里面的内容。然后声明文件变量
    var
      f:TextFile;
    begin
      AssignFile(f,filePath);
      ReWrite(f);
      ...
      ...
      for j:=1 to FieldCount-1 do  //插入一条记录
        begin
          str:=Trim(Fields[j].AsString);
          k:=length(trim(Str));
          for i:=k+1 to Fields[j].DataSize-1 do
          begin
            Str:=Str+' ';
          end;
          Write(f,Str);//写入
        end;
       Write(f,#13#10);//换行
       ...
       ...
       CloseFile(f);
    end;
      

  2.   

    var
      path,sql:string;
      str_con:string;
    begin
    conn.Close ;
    path:=extractfilepath(application.ExeName );
    str_con:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source=' + path + '\my.mdb;Persist Security Info=False;Jet OLEDB:Database Password=test;
    conn.ConnectionString :=str_con;
    try
      conn.connected:=true;
      showmessage('ok');
    except
      showmessage('error');
    end;//生成TXT文本文件
    Sql:='select * into [text;Database=' + path + '].test.txt' + ' from eu_onipot';
    conn.Execute(sql);
    showmessage('over txt');
      

  3.   

    var
      path,sql:string;
      str_con:string;
    begin
    conn.Close ;
    path:=extractfilepath(application.ExeName );
    str_con:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source=' + path + '\my.mdb;Persist Security Info=False;Jet OLEDB:Database Password=test;
    conn.ConnectionString :=str_con;
    try
      conn.connected:=true;
      showmessage('ok');
    except
      showmessage('error');
    end;//生成TXT文本文件
    Sql:='select * into [text;Database=' + path + '].test.txt' + ' from eu_onipot';
    conn.Execute(sql);
    showmessage('over txt');
      

  4.   

    with ADODataSet1 do
    try
      Close;
      CommandText:=' select * from table ';
      Open;
      SaveToFile('c:\x.txt');
      Close;
    except
    end;
      

  5.   

    有专门这样的控件,你可到www.51delphi.com去找,它可以把dataset的数据倒出文本、Excel,Word,html等多种格式,名字我不太记得了。
      

  6.   

    var
    f:textfile
    i:integer
    begin
    while not adotable1.eof do
    begin
    //加入qqqeee(zipple) 的内容
    end;
    end;
      

  7.   

    我这样做了,总是提示filename有错误。
      

  8.   

    我这样做了,总是提示filepath有错误。
      

  9.   

    我这样做了,总是提示[Error] Untdaochu.pas(231): Undeclared identifier: 'filePath'