1
    ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;   Data Source='" + fileName + "';  Extended Properties=Excel 5.0"        

    Dim ExcelConnection As System.Data.OleDb.OleDbConnection
    ExcelConnection = New System.Data.OleDb.OleDbConnection(ConnectionString)

    ExcelQuery = "Select * from [Sheet2$]"
    Dim ExcelCommand As New System.Data.OleDb.OleDbCommand(ExcelQuery, ExcelConnection)
    ExcelConnection.Open()

    Dim ExcelReader As System.Data.OleDb.OleDbDataReader
    ExcelReader = ExcelCommand.ExecuteReader()

    While (ExcelReader.Read)


    End While
    ExcelConnection.Close()
    ExcelReader.Close()

Error occurs on line

         ExcelConnection.Open()
       External table is not in the expected format.

PLease help
Thank you

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
ConfusedCoder
  • 175
  • 1
  • 6
  • 17
  • Please show us the connection string. Possible duplicate of http://stackoverflow.com/questions/1139390/excel-external-table-is-not-in-the-expected-format – Olaf Jun 12 '11 at 10:48

1 Answers1

2

Use

public static string connStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileName + ";Extended Properties=Excel 12.0;";

as your connection string. Find more information here: Excel "External table is not in the expected format.".

Community
  • 1
  • 1
Olaf
  • 10,049
  • 8
  • 38
  • 54