Error while reading Excel sheet from C#:
ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
How to solve this?
This is my code:
OdbcConnection oConn = new OdbcConnection();
oConn.ConnectionString =
"Provider=MSDASQL.1;data source=D:\\Para_Lalit\\sample.xlsx;Extended Properties='Excel 12.0;Format=xlsx'";
OdbcCommand oComm = new OdbcCommand();
oComm.Connection = oConn;
oComm.CommandText = "Select * From [aa$]";
try
{
DataSet ds = new DataSet();
OdbcDataAdapter oAdapter = new OdbcDataAdapter(oComm);
oConn.Open();
oAdapter.Fill(ds);
dataGridView1.DataSource = ds;
dataGridView1.DataBind();
dataGridView1.DataMember = ds.Tables[0].TableName;
}