none
I tried to open a Excel file using the code below:but iam getting error at con.open()? RRS feed

  • Question

  • string excelfilename = openFileDialog1.FileName;

    string connString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+excelfilename+@";Extended Properties=Excel 8.0;HDR=Yes;IMEX=1";

    System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection(connString);

    conn.Open();

    System.Data.OleDb.OleDbCommand selectAllComand = new System.Data.OleDb.OleDbCommand("SELECT * FROM [sheet1$]");

    System.Data.OleDb.OleDbDataReader excelReader = selectAllComand.ExecuteReader();

    conn.Close();

    Wednesday, June 6, 2007 11:23 AM

All replies

  • Please use the post button in the appropiate forum for your question. I moved this here as it has to do with data access in .NET.

     

    Please provide more details about what error it is that you get? What description does it have?

     

    Wednesday, June 6, 2007 12:26 PM

  • What is the error?
    Wednesday, June 6, 2007 3:14 PM
  • You have not posted the error, but I believe you need to put part of the connection string for the Extended Properties into additional double quotes. It is some sort of string inside another string, like

     

    string connString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+excelfilename+@";Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1""";

    Thursday, June 7, 2007 10:49 AM
    Moderator