我有以下代码:
Imports System.Data.OleDb
Private Sub getData()
Dim connStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\rawData.xlsx;Extended Properties=Excel 12.0 Xml;"
Dim oleConn As New OleDbConnection(connStr)
Dim query As String = "SELECT * FROM [Sheet1$]"
Dim cmd As New OleDbCommand(query, oleConn)
Dim reader As OleDbDataReader
oleConn.Open() ' Getting Exception Here !!
reader = cmd.ExecuteReader()
Do While reader.Read()
InputOutput.print(reader.GetString(0)) ' Prints the 1st column.
Loop
reader.Close()
oleConn.Close()
End Sub
异常文本:无法找到可安装的ISAM。
我做错了什么?
请帮助,我是新手!
答案 0 :(得分:1)
将我的连接字符串更改为:
Dim connStr As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\rawData.xlsx;Extended Properties=""Excel 12.0 XML;"""
它就像一个魅力......!
答案 1 :(得分:0)
检查此代码,其工作正常。
cn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;data source =D:\ODD_2015\Counselling.xlsx;extended properties=excel 12.0;"
cn.Open()