End Google Ads 201810 - BS.net 01 --> Hi there,

I'm trying to read .xls file using OleDb connection. I have two .xls files generated from SAP (actually these are Unicode text files saved as .xls) with two different names. When I execute my code I can only open one file, the second one gives an error:

System.Data.OleDb.OleDbException: The Microsoft Jet database engine could not find the object 'sheetName$'. Make sure the object exists and that you spell its name and the path name correctly.

Both files contains only one sheet which has the same name as the file itself. I've checked the spelling several times and even changed it manually but it doesn't work on one file. Even when I saved the file as proper Excel file. Here's the code I'm using:


//opens file and fills the DataGridView with data from file
string fileNameWithExt;
string fileNameWithoutExt;
int fileNameLength = 0;
int cutExtension = 4;
fileNameWithExt = openFileDialog1.SafeFileName;
fileNameLength = fileNameWithExt.Length;
fileNameWithoutExt = fileNameWithExt.Remove(fileNameLength - cutExtension);

OleDbConnection aConnection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\" + fileNameWithExt + ";Extended Properties=Excel 8.0");
aConnection.Open();

DataTable sampleDataTable = new DataTable();

//clears data table and dataGridView before creating a new one
dataGridView1.DataSource = null;
sampleDataTable.Clear();
sampleDataTable.Columns.Clear();


OleDbDataAdapter oleDbCommand = new OleDbDataAdapter("Select * from ["+fileNameWithoutExt+"$]", aConnection);
oleDbCommand.Fill(sampleDataTable);


I hope somebody can point me in the right direction as I checked plenty of posts and know that something is wrong with the sheet name but can find the issue.

Regards,