Reputation: 1
When I run the code below I get the following error:
System.Data.OleDbException of {"External table is not in the expected format."}
I have tried all the different Extended Properties:
With HDR=NO
and without. With IMEX=1
and without.
With HDR=NO
and without. With IMEX=1
and without.
The XLS file is initially downloaded from a web page to the local hard drive of a computer. My web app then uploads it to the a different web server using the FileUpload control (The file is not locked, I tested for that). Then the code below is called.
The only resolution I have found is this - If I simply open the file in Excel (I have Office 2013) and then close Excel, the code works! No OleDbException! I'm not saving the file in a different format, I simply open the file in Excel and close it!
What gives? I haven't been able to find any information about what the expected file format is or if that is really even the issue. And why would the query work simply because the file has been opened with Excel?
Anyway, any assistance would be greatly appreciated. Here is the code:
DataSet ds = new DataSet();
string findTypeConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filePath + "; Extended Properties=\"Excel 12.0;HDR=NO\"";
string findTypeQuery = "SELECT * FROM [Sheet1$E1:E1]";
using(OleDbConnection findTypeCon = new OleDbConnection(findTypeConnectionString)){
using(OleDbDataAdapter findTypeDa = new OleDbDataAdapter(findTypeQuery, findTypeCon)){
findTypeDa.Fill(ds);
}
}
The OleDbException occurs at:
findTypeDa.Fill(ds);
edit - Yes, I am selecting the contents of a single cell in the xls file.
Upvotes: 0
Views: 1136