tags:

views:

102

answers:

1

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;
     }
A: 

Take a look for a dll called OfficeOpenXML, there is an opensource excel package you can download to manipulate Excel files

Israfel