Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The code that I can, the error message "Format of the initialization string does not conform to specification starting at index 92." on the "Dim conn As OleDbConnection = New OleDbConnection (strconn)" how to fix it?
VB
Public Shared Function excel(ByVal path As String) As DataTable
       Dim dtexcel As New DataTable()
       Dim headers As Boolean = False
       Dim HDR As String
       Dim strConn As String

       If headers = False Then
           HDR = "Yes"
       Else
           HDR = "No"
       End If

       If path.Substring(path.LastIndexOf(".")).ToLower() = ".xlsx" Then
           strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & path & ";Extended Properties=""" & "Excel 12.0;HDR=" & HDR & ";IMEX=0;"
       Else
           strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & path & ";Extended Properties=" & """Excel 8.0;HDR=" & HDR & ";IMEX=0;"
       End If
       Dim conn As OleDbConnection = New OleDbConnection(strConn)

       conn.Open()
       Dim Stable As DataTable = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, New Object() {vbEmpty, vbEmpty, vbEmpty, "TABLE"})

       Dim Srow As DataRow = Stable.Rows(0)
       Dim sheet As String = Srow("Table_name").ToString()
       If Not sheet.EndsWith("_") Then
           Dim query = "select * from [" & sheet & "]"
           Dim daexcel As OleDbDataAdapter = New OleDbDataAdapter(query, conn)
           dtexcel.Locale = System.Globalization.CultureInfo.CurrentCulture
           daexcel.Fill(dtexcel)

       End If
       conn.Close()
       Return dtexcel
   End Function
Posted

1 solution

Actually the error tells what the problem is. You haven't terminated 'Extended Properties' with a double quote. End connection strings with ";IMEX=0;"""
 
Share this answer
 
Comments
Gandi Musen Sejati 3-Mar-14 22:43pm    
Thanks ,

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900