Hi guys, here im trying to read excel 2007 spreadsheet file. I have this code which is similar to a piece of code i picked here, i just changed few things to accommodate my needs. When im running the program i recieve these 2 errors :
1. could not find Installable ISAM.
2. and 2nd error is it cant find table0.
Please review this code then tell me where do i went wrong.
//I declare the connection string
public string GetConnection()
{
string constr = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\Data\GraduatesList.xlsx;Extended Properties="+"Excel 12.0 Xml;HDR=YES";
return constr;
}
public DataTable ReadRecords()
{
DataSet dsUserData = new DataSet();
try
{
string query = "Select ID,Surname From [Sheet1$]";
using (OleDbConnection Connection = new OleDbConnection(GetConnection()))
{
using (OleDbDataAdapter DataAdapter = new OleDbDataAdapter(query, Connection))
{
DataAdapter.Fill(dsUserData, "UserData");
DataAdapter.AcceptChangesDuringFill = false;
DataAdapter.Dispose();
Connection.Close();
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
return dsUserData.Tables[0];
}