2017-02-14 37 views
1

當我想導入片擅長於C#應用程序的錯誤的出現,沒有在表的一個或多個必需參數的給定值的Excel

ERROR爲「沒有對於給定的值的一個或多個必需參數」 。

我使用MS Excel的C#。這是我的代碼

OpenFileDialog openFileDialog1 = new OpenFileDialog(); 
     openFileDialog1.FileName = ""; 
     openFileDialog1.Filter = "Excel File Sheet |*.xls; *.xlsx"; 
     try 
     { 
      if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) 
      { 

       string path = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + openFileDialog1.FileName + ";Extended Properties=\"Excel 8.0;HDR=Yes;\";"; 
       OleDbConnection conn = new OleDbConnection(path); 
       OleDbDataAdapter da = new OleDbDataAdapter("SELECT Date, PF, [Agent Name], TL, Supervisor, [Sum Under], [Sum Over], [Out of Adherence], Sch, Sum([Out of Adherence %]*100), Sum((100-(100*[Out of Adherence %]))) AS [Adherence % Daily] FROM [Sheet1$] GROUP BY Date, PF, [Agent Name], TL, Supervisor, [Sum Under], [Sum Over], [Out of Adherence], Sch, [Out of Adherence %]", conn); 
       DataTable dt = new DataTable(); 
       da.Fill(dt); 
       dataGridView1.DataSource = dt; 


      } 
     else 
       return; 

     } 
     catch(FieldAccessException ex) 
     { 
      MessageBox.Show("ERROR" + ex); 
     } 

請幫我這個錯誤,

感謝所有..

+0

什麼樣的錯誤?編譯時間或運行時間?它出現在哪裏?在這裏檢查一下 - http://stackoverflow.com/questions/2378763/no-value-given-for-one-or-more-required-parameters,然後檢查你的代碼是否爲'Null'值。 – Vityata

回答

1

這個錯誤通常是指在你的SELECT語句丟失或拼寫錯誤值。

仔細檢查所有列名稱。

相關問題