Please, read my comment first.
1. You forgot to open connection:
oOleDbConnection = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties='Excel 12.0';");
oOleDbConnection.Open();
oOleDbDataAdapter = new OleDbDataAdapter("select * from [sheet1$]", oOleDbConnection);
2. A
path
variable should be initiated this way:
string path = @"C:\Folder1\Foder2\FileName.xlsx";
string path = "C:\\Folder1\\Foder2\\FileName.xlsx";
3. Check if
sheet1
exists in a collection of sheets!
4. Use specific connection string for each Excel file (depending on extension):
See:
Microsoft ACE OLEDB 12.0 Connection Strings - ConnectionStrings.com[
^]
For xlsx files:
string constr = string.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties='Excel 12.0 Xml';", path);