2013-10-31 147 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

相關問題