我在'/'应用程序中收到服务器错误。
无效的论点。
描述:执行当前Web请求期间发生了未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。
异常详细信息:System.Data.OleDb.OleDbException:参数无效。
当我尝试使用MyCommand.Fill
阅读DataSet
这是我的代码
Dim sheets as new List(Of String)(New String(){"po"})
Dim MyConnection As System.Data.OleDb.OleDbConnection
Dim DtSet As System.Data.DataSet
Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
MyConnection = New System.Data.OleDb.OleDbConnection("provider=Microsoft Office 12.0 Access Database Engine OLE DB Provider;Data Source=" & filepath & ";Extended Properties=Excel 8.0;")
for p as integer = 0 to sheets.count - 1
dim dt as DataTable
MyCommand = New System.Data.OleDb.OleDbDataAdapter("Select * from ["& sheets(p) & "$]", MyConnection)
DtSet = New System.Data.DataSet
MyCommand.Fill(DtSet)
dt = DtSet.Tables(0)
if p > 0
response.write(sheets(p))
end if
next
MyConnection.Close()
答案 0 :(得分:0)
我有一些顾虑:
首先尝试通过调用 MyConnection.Open()
打开连接Dim sheets as new List(Of String)(New String(){"po"})
Dim MyConnection As System.Data.OleDb.OleDbConnection
Dim DtSet As System.Data.DataSet
Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
MyConnection = New System.Data.OleDb.OleDbConnection("provider=Microsoft Office 12.0 Access Database Engine OLE DB Provider;Data Source=" & filepath & ";Extended Properties=Excel 8.0;")
MyConnection.Open() '<-------------------- open the connection here
for p as integer = 0 to sheets.count - 1
dim dt as DataTable
MyCommand = New System.Data.OleDb.OleDbDataAdapter("Select * from ["& sheets(p) & "$]", MyConnection)
DtSet = New System.Data.DataSet
MyCommand.Fill(DtSet)
dt = DtSet.Tables(0)
if p > 0
response.write(sheets(p))
end if
next
MyConnection.Close()