Click here to Skip to main content
15,907,183 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
An error message displays while executing below c# source code:

using System.Xml;
Excel = Microsoft.Office.Interop.Excel;

  System.Data.OleDb.OleDbConnection MyConnection;
            System.Data.DataSet ds;
            System.Data.OleDb.OleDbDataAdapter MyCommand;
            MyConnection = new System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;Data Source='d:\\Mail_ids.xls';Extended Properties=Excel 8.0;");
            MyCommand = new System.Data.OleDb.OleDbDataAdapter("select * from [Sheet1$]", MyConnection);
            MyCommand.TableMappings.Add("Table", "Product2");
            ds = new System.Data.DataSet();
            MyCommand.Fill(ds);   // this line shows error
            MyConnection.Close();
            ds.WriteXml("Product2.xml");


And the error message is :

"The Microsoft Jet database engine could not find the object 'Sheet1$'. Make sure the object exists and that you spell its name and the path name correctly."

Where its confirmed that the specified Excel file exists at the said location.
What is the reason for the error and what should be the right code?
Posted

 
Share this answer
 
Comments
Espen Harlinn 17-Jul-11 17:17pm    
Will probably do the trick, my 5
As the error message says Microsoft Jet database engine could not find the object 'Sheet1$, hence make sure the Sheet1 exists in your excel file.

Second thing here: 'd:\\Mail_ids.xls' make sure the file name is correct and the file extension is .xls not .xlsx.

hope it helps :)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900