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:
- string path = Directory.GetCurrentDirectory();
- string finalFile = path + FileName;
- string connString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + finalFile + ";Extended Properties=\"Excel 12.0 Xml;HDR=YES;\"";
- OleDbConnection conn = new OleDbConnection(connString);
- if (conn.State == ConnectionState.Closed)
- conn.Open();
- DataTable dt = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
- foreach (DataRow roww in dtEmployeeDetails.Rows)
- {
- string query = "text query";
- OleDbCommand cmd = new OleDbCommand(query, conn);
- int dr = cmd.ExecuteNonQuery();
- }
- conn.Close();
- 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".