Reading Excel using Odbc

A

Alan White

Hello, I need to read the excel file using Odbc, but when I run my code, I
got the following error:

"Error: ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not
found and no default driver specified"

Could someone please tell me what is wrong with this?. Here is the code I
use to read the file.

I already include the Microsoft.Data.Odbc and add reference to Excel10.
Thank you

String sConnectionString = "Provider=MSDASQL;Driver={Microsoft Excel
Driver(*.xls)};DBQ=c:\\temp\\Sale_Test.xls;;;Extended
Properties=Excel10.0;HDR=No;";

// Create connection object by using the preceding connection string.

objConn = new OdbcConnection(sConnectionString);

OdbcCommand objCmdSelect =new OdbcCommand();



objCmdSelect.Connection = objConn;

objCmdSelect.CommandText = "Select * From [Week1$]";

objConn.Open();
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top