excel read file

G

Guest

I am trying to read an excel file. Here is my code
string Conn ="Provider=Microsoft.Jet.OLEDB.4.0;Data Source =
G:\\\\NA\\Stamford\\Technology\\Information
Security\\DATA_ENTITLEMENTS!\\G_Drive_Entitlements_STM_2005.xls;" +
"Exteneded Properties=Excel 8.0;";
OleDbConnection dbConn = new OleDbConnection(Conn);
dbConn.Open ();
OleDbCommand Cmd = new OleDbCommand("Select * From [Sheet1$]", dbConn);
OleDbDataAdapter Da = new OleDbDataAdapter();
Da.SelectCommand = Cmd;
DataSet Ds = new DataSet();
Da.Fill(Ds);
dg.DataSource = Ds.Tables[0];
dbConn.Close ();

I get the error here: OleDbCommand Cmd = new OleDbCommand("Select * From
[Sheet1$]", dbConn);
Please help
 
G

Guest

Freddy,

I believe that the only thing wrong with your code is you have misspelled
the word extended. If you replace

"Exteneded Properties=Excel 8.0;";

with

"Extended Properties=Excel 8.0;";

It should work fine. One other thing...To avoid all of those escape
sequences you can use verbatim strings instead. Try @"C:\temp\test.xls"
instead of "C:\\temp\\test.xls".

Hope this helps.
 

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

Similar Threads


Top