delphi怎么连接dbf表,以及对dbf表添加数据?
比如我从EXCEL中去出两列数据,然后用循环添加到dbf表中!

解决方案 »

  1.   

    通过ODBC建一个指向*.dbf表的连接
    然后.....就不用说了
      

  2.   

    最简单的方法就是下载Halcyon6控件,不需配置ODBC
      

  3.   

    我不想用ODBC,有没有其他办法?
    有没有相关的代码?
      

  4.   

    不用ODBC那你就要去www.google.com 
    呵呵,自己去找吧
      

  5.   

    用BDE和ODBC啊查查书,上面多得要命
      

  6.   

    对dbf表,delphi可用bde/odbc/ado来连接.
    bde:
    http://community.csdn.net/Expert/topic/4449/4449770.xml?temp=.3610956
    用ado,联接串为:
    Provider=Microsoft.Jet.OLEDB.4.0;Password="";Data Source=d:\temp;Extended Properties=dbase 5.0;Persist Security Info=True
      

  7.   

    用ADOConnection连接数据库,用ADODateSet组件执行SQL语句
      

  8.   

    谢谢各位!我也是想用ADO连接,这样是不是方便,到别的机器上不用配置什么的。
    有没有更详细的例子?
      

  9.   

    我连接的是VFP数据库,代码如下;
    procedure TForm1.Button1Click(Sender: TObject);
    var vfpdbfpath,sql:string;
    begin
       vfpdbfpath:='F:\新建文件夹\database\FOXUSER.DBF' ;
      try
      ADOConnection1.Close;
      adoconnection1.ConnectionString:='Provider=MSDASQL.1;'
                                     + 'Persist Security Info=False;'
                                     + 'Extended Properties='
                                     + '"Driver={Microsoft Visual FoxPro Driver};'
                                     + 'UID=;'
                                     + 'SourceDB=' + vfpdbfpath //这里的变量是DBF文件名
                                     + ';SourceType=DBF;'
                                     + 'Exclusive=No;'
                                     + 'BackgroundFetch=Yes;'
                                     + 'Collate=Machine;'
                                     + 'Null=Yes;'
                                     + 'Deleted=Yes;"';
      ADOConnection1.Open;
      if ADOConnection1.Connected  then
        begin
           application.MessageBox('数据库连接成功!','系统提示');
           sql:='select * from FOXUSER';
           adoconnection1.Execute(sql) ;
        end;
      except
           application.MessageBox('数据库连接失败,请确认无误后重试!','提示:')
      end;
    end;
    ====================================================================================
    我运行的时候提示连接成功,但是到adoconnection1.Execute(sql);就会出错。
    我觉得还是连接的不对,因为我把路径改为D盘下面它也提示成功,D盘下更本就没有那个表。
    各位大侠帮帮啊。
      

  10.   

    你的ADO是通过ODBC连的,改用我的连接串试试:
    adoconnection1.ConnectionString:='
    Provider=Microsoft.Jet.OLEDB.4.0;Password="";Data Source='+vfpdbfpath+';Extended Properties=dbase 5.0;Persist Security Info=True';
    另外vfpdbfpath是路径名,不能带文件名
     vfpdbfpath:='F:\新建文件夹\database\'
      

  11.   

    谢谢,用keiy() 提供的方法成功了。