我想读一个Excel页面,但我得到以下错误:VB.net读取Excel的页面
Input string was not in a correct format.Couldn't store <555-555-5555> in PHONE_NUM Column. Expected type is Double.
看来,OLEDB命令期待列的类型为双(但是,在事实上,这是一个电话号码字符串)。我想我会在某处读到这种情况,因为该命令看起来像列中的第一对项目,并确定了该类型应该基于哪个类型。无论如何总是以字符串形式读取所有值?
这是我使用的代码:
Dim connection As OleDb.OleDbConnection
Dim command As OleDb.OleDbCommand
Dim adapter As New OleDb.OleDbDataAdapter
Dim connString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + myFile + ";Extended Properties=Excel 12.0;"
Dim pgOne As String = "Page1$"
Dim pgTwo As String = "Page2$"
Dim selectOne As String = "SELECT * FROM [" & pgOne & "] WHERE COL1<>''"
Dim selectTwo As String = "SELECT * FROM [" & pgTwo & "]"
connection = New OleDb.OleDbConnection(connString)
Try
If connection.State = ConnectionState.Open Then
Else
connection.Open()
End If
command = New OleDb.OleDbCommand(selectOne, connection)
adapter.SelectCommand = command
adapter.Fill(ds, "Table1")
adapter.SelectCommand.CommandText = selectTwo
adapter.Fill(ds, "Table2")
Catch ex As OleDb.OleDbException
Finally
adapter.Dispose()
If (Not command Is Nothing) Then
command.Dispose()
End If
connection.Close()
End Try
感谢您的回复。我尝试了两个建议,但得到相同的错误“无法找到可安装的ISAM”。当试图打开连接时。有什么想法吗? – jason
那么,ISAM错误是固定的(http://stackoverflow.com/questions/8120699/could-not-find-installable-isam)但我仍然有问题。使用IMEX = 1不起作用。尝试使用HDR = NO会导致出现另一个错误“没有给出一个或多个必需参数的值”。 – jason
尝试IMEX = 1; HDR = NO;在一起 - 仍然没有骰子,那么我会发现有关事物的Schema方面 –