I am trying to read an Excel page but I get the following error:
Input string was not in a correct format.Couldn't store <555-555-5555> in PHONE_NUM Column. Expected type is Double.
It seems that the oledb command is expecting the column to be of type double (but, in fact, it is a string for phone numbers). I think I read somewhere that this happens because the command looks as the first couple of items in the column and determines what the type should be based off of that. Is there anyway to always read all values in as a string?
This is the code I am using:
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