我现在用一个opendialog,一个adoquery准备打开dbf文件  程序是这样写的这段写的是连接方法。
procedure TForm5.Button2Click(Sender: TObject);
begin
    if (opendialog1.Execute) then
    begin
       adoconnection1.Close;
       adoconnection1.ConnectionString:='Provider=MSDASQL.1;Driver=Microsoft Visual Foxpro Driver;SourceDB='+opendialog1.FileName+';SourceType=DBF';
       adoconnection1.Open;
    end;
end;
这段是显示dbf文件中的数据
procedure TForm5.Button3Click(Sender: TObject);
begin  with adoquery1 do
  begin
      close;
      sql.Clear;
      sql.Add('select * from ['+opendialog1.FileName+']') ;
      open;
  end;
end;
但是打开总显示出做  请问为什么

解决方案 »

  1.   

    adoConnection连接正确的
    sql.Add('select * from ['+opendialog1.FileName+']') ; 
    opendialog1.FileName是包括带路径的文件名,这样的表名肯定是不对了
      

  2.   

    procedure TForm5.Button2Click(Sender: TObject); 
    begin 
      if (opendialog1.Execute) then 
        begin 
          adoconnection1.Connected:=False;
          adoConnection1.ConnectionString:='Provider=MSDASQL.1;Extended Properties="Driver={Microsoft Visual Foxpro Driver};SourceType=DBF;SourceDB='+opendialog1.FileName+'"'; 
          adoconnection1.Connected:=True;
        end; 
    end; procedure TForm5.Button3Click(Sender: TObject); 
    begin 
      with adoquery1 do 
      begin 
          close; 
          sql.Clear; 
          sql.Text:='select * from '+Copy(ExtractFileName(OpenDialog1.FileName),1,Length(ExtractFileName(OpenDialog1.FileName))-4); 
          open; 
      end; 
    end;