I have an Excel 2007 file "my.xlsx" and a sheet named "States", and I have the following code
using (OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\my.xlsx;Extended Properties='Excel 12.0 Xml;HDR=NO'"))
{
OleDbCommand cmd = new OleDbCommand("select * from [States]", con);
con.Open();
OleDbDataReader reader = cmd.ExecuteReader();
while(reader.Read())
Console.WriteLine(reader[0]);
}
It keeps throwing exception saying "The Microsoft Office Access database engine could not find the object 'States'. Make sure the object exists and that you spell its name and the path name correctly.".
Could someone help to see what's wrong with my code please?