2013-10-31 100 views
1

我试图运行以下代码来访问文件夹中的DBF文件。如果RF10.dbf文件的名称:执行查询时在给定路径中找不到DBF文件

foxpro = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Documents and Settings\\xxxxxx\\xxxxx\\xxxxx\\;Extended Properties=dBASE IV;User ID=ADMIN;Password=;"); 


      try 
      { 
       foxpro.Open(); 
       label4.Text = "Connected"; 
      } 
      catch (OleDbException oex) 
      { 
       label4.Text = "Connection Failed"; 
       // connection error 
      } 

并执行以下查询:

OleDbCommand fpcmd = new OleDbCommand(); 
          fpcmd.Connection = foxpro; 
          fpcmd.CommandText = "SELECT * FROM RF10.DBF WHERE SRNO='RDDFT000108'"; 
          fpcmd.CommandType = CommandType.Text; 
          fpcmd.CommandTimeout = 300; 



          try 
          { 
           acompressor = (String)fpcmd.ExecuteScalar(); 
           // SqlDataAdapter da = new SqlDataAdapter(cmd1); 
           //DataSet ds = new DataSet(); 
           // da.Fill(ds); 
           if (acompressor == null) 
            acompressor = ""; 


           if (acompressor.Equals(compressor)) 
           { 
            MessageBox.Show("Serial number and compressor number is a correct match."); 
            textBox1.Text = ""; 
            textBox2.Text = ""; 
           } 
           else 
           { 

            MessageBox.Show("Serial number and compressor number DO NOT match."); 
            textBox1.Text = ""; 
            textBox2.Text = ""; 
           } 
          } 
          catch (OleDbException oex) 
          { 
           Console.Write(fpcmd.CommandText); 
           Console.Write(oex.Message); 
           // command related or other exception 
          } 

在执行查询它提供了以下错误的问题是:

The Microsoft Jet database engine could not find the object 'RF10.DBF'. Make sure the object exists and that you spell its name and the path name correctly.

但是,有一个名为RF10.dbf的文件。我哪里错了?

+1

只读?权限? – Steve

+0

我使用dbf查看器浏览了该文件。我把它放在本地驱动器中。 – Salik

回答

0

它可能是您对文件夹或文件的访问权限。你检查过了吗?

+0

我可以访问文件夹和文件,我使用dbf viewer – Salik

1

尝试使用完整的文件路径:

fpcmd.CommandText = "SELECT * FROM 'D:\some_folder\RF10.DBF' WHERE SRNO='RDDFT000108'"; 
+0

nope浏览它,它说它不是一个有效的名称。 – Salik

1

IIRC你不包括在查询扩展:

fpcmd.CommandText = "SELECT * FROM RF10 WHERE SRNO='RDDFT000108'"; 
+0

之前尝试过,没有工作。 – Salik

相关问题