请问如何把已经读入ADOQuery的数据集导出成visual foxpro 6.0的dbf格式呢?dbf表事先不存在,要在程序运行中创建.翻看了以前的一些帖子,还是不得要领,请各位不吝赐教,谢谢.顺便问一下如果dbf表结构事先已经存在,那要怎么搞?

解决方案 »

  1.   

    Table_DBF.Close;//Active:=false;
                            Table_DBF.TableName := '..\Export\qqtel.dbf';
                            Table_DBF.TableType := ttFoxPro;
                            try
                                    Table_DBF.Active:=True;
                                    if not Table_DBF.eof then
                                    begin
                                            Table_DBF.Close;
                                            Table_DBF.EmptyTable;
                                            Table_DBF.Open;
                                    end;
                            except
                                    Table_DBF.Close;
                                    Application.MessageBox('数据库错误','错误', MB_OK+MB_ICONERROR);
                                    exit;
                            end;
                            QueryCustomer.First;
                            while not QueryCustomer.Eof do
                            begin
                                    //插入DBF文件
                                    try
                                            Table_DBF.Append;
                                            Table_DBF.FieldValues['tele'] := QueryCustomer.FieldByName('telephone').AsString;
                                            Table_DBF.Post;
                                    except
                                            Table_DBF.Close;
                                            exit;
                                    end;
                                    QueryCustomer.Next;
                            end;
                            Table_DBF.Close;
      

  2.   

    谢谢楼上的,这是dbf结构已知的情况吧,已搞定,谢谢!
    对于dbf事先不存在的情况我还有个疑问,我小改了一个delphi自带的在程序运行时建表的例子:
    with Table1 do begin
      Active := False;  
      \\DatabaseName := 'DBDEMOS';
      TableType := ttFoxPro;
      TableName := 'a.dbf';  { Don't overwrite an existing table }  if not Table1.Exists then begin
        { The Table component must not be active }
        { First, describe the type of table and give }
        { it a name }
        { Next, describe the fields in the table }
        with FieldDefs do begin
          Clear;
          with AddFieldDef do begin
            Name := 'Field1';
            DataType := ftInteger;
            Required := True;<===========这个Required属性,设为false则可以正常建表,而设成True则提示表结构invalid,异常退出.
          end;
          with AddFieldDef do begin        Name := 'Field2';
            DataType := ftString;
            Size := 30;
          end;
        end;
        { Next, describe any indexes }
        with IndexDefs do begin
          Clear;
            with AddIndexDef do begin        Name := 'Fld2Indx';
            Fields := 'Field2';
            Options := [ixCaseInsensitive];
          end;
        end;
        { Call the CreateTable method to create the table }
        CreateTable;
      end;
    end;把其中AddFieldDef的Required属性设为false可以正常建表,而设为true则提示表结构非法,异常退出.这是怎么回事呢?该怎么办?谢谢