本文介绍了如何将excel导入数据表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用的代码,错误消息初始化字符串的格式不符合从索引92开始的规范。关于Dim conn As OleDbConnection = New OleDbConnection(strconn)如何修复它?

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?

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

推荐答案


这篇关于如何将excel导入数据表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 02:43