I'm getting the following Error:
ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
The code is written as :
protected void btnconnect_Click(object sender, EventArgs e)
{
OdbcConnection oConn = new OdbcConnection();
oConn.ConnectionString = "Provider=MSDASQL.1;data source=D:\\Parallelminds_Lalit\\Lalit Profile\\Other\\Old Back up\\Lalit PC Bkp\\Projects\\All SBTS backup\\SBTS\\SBTS1.0\\Bin\\sample.xlsx;Extended Properties='Excel 12.0;Format=xlsx'";
OdbcCommand oComm = new OdbcCommand();
oComm.Connection = oConn;
oComm.CommandText = "Select * From [aa$]";//aa is sheet name
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;
}
finally
{
oConn.Close();
}
}
Why am I getting this error?