Reputation: 1
I'm getting Server Error in '/' Application.
Invalid argument.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.OleDb.OleDbException: Invalid argument.
when I try to use MyCommand.Fill
to read the DataSet
Here's my code
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()
Upvotes: 0
Views: 344
Reputation: 4542
I have a few concerns:
First try to open the connection by calling 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()
Upvotes: 0