none
Format of the initialization string does not conform to specification starting at index 0". RRS feed

  • Question

  • When I use the click the view excel data button I receive the error "Format of the initialization string does not conform to specification starting at index 0".

     

    Here's my code.  Can you help me? 

     

    protected OleDbCommand ExcelConnection()

    {

     

    //Get file name from session variable
     

     

    String sFileName;

    sFileName = (

    string)(Session["myFileName"]);

     

    // Connect to the Excel Spreadsheet
     

     

    string xConnStr;

     

    string xConnStr00 = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + (sFileName) + ";" + "Extended Properties=Excel 8.0;";

     

    string xConnStr01 = "Provider='Microsoft.ACE.OLEDB.12.0',;" + "Data Source=" + (sFileName) + ";" + "Extended Properties=Excel 8.0;";

     

     

    //Assign connection string based on radio button selection

     

    if(radExcelVersion.SelectedValue == "0")

    xConnStr = xConnStr00;

    // Excel 1999-2002 connection string

     

    else

    xConnStr = xConnStr01;

    // Excel above 2002 connection string

     

     

    // create your excel connection object using the connection string

     

    OleDbConnection objXConn = new OleDbConnection(xConnStr);(Here is coming that error)

    objXConn.Open();

     

    // use a SQL Select command to retrieve the data from the Excel Spreadsheet

     

    // the "table name" is the name of the worksheet within the spreadsheet

     

    // in this case, the worksheet name is "Members" and is coded as: [Members$]

     

    OleDbCommand objCommand = new OleDbCommand(" select * from [Membership$]", objXConn);

     

    return objCommand;

    }

    • Moved by Min ZhuModerator Wednesday, July 13, 2011 9:52 AM off-topic (From:64-Bit .NET Framework Development.)
    Monday, July 11, 2011 3:12 PM

Answers

All replies