Gaurav Arora

Gaurav Arora

  • NA
  • 14
  • 1.2k

External table is not in the expected format

Aug 28 2019 9:17 AM
I have around 10 excel file in a directory and based on the date I am trying to sort and compare 2 files at a time using foreach loop using C# console application in Visual Studio 2019.

Below is the code:
 
  1. string path = Directory.GetCurrentDirectory();  
  2. string finalFile = path + FileName;  
  3. string connString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + finalFile + ";Extended Properties=\"Excel 12.0 Xml;HDR=YES;\"";  
  4. OleDbConnection conn = new OleDbConnection(connString);  
  5. if (conn.State == ConnectionState.Closed)  
  6. conn.Open();  
  7. DataTable dt = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);  
  8. foreach (DataRow roww in dtEmployeeDetails.Rows)  
  9. {  
  10. string query = "text query";  
  11. OleDbCommand cmd = new OleDbCommand(query, conn);  
  12. int dr = cmd.ExecuteNonQuery();  
  13. }  
  14. conn.Close();  
  15. conn.Dispose();  
I am sometime successfully able to execute the code, but sometime i get the error as "External table is not in the expected format".

Answers (1)