You can try it this way :
- Set connection string to read excel file without header (
HDR=NO
). Column name will be autogenerated for each column starting fromF1
toFn
. - Fill
DataTable
the way you currently do - Remove first row from
DataTable
since it actually column header name in excel
With that you'll get the text instead of DateTime value from excel. In my understanding, that because excel determines data type from the first row. So with this hack the first row is a text (the header) hence decided that the column is of type text/string.
MyConnection = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" & _
path & "';Extended Properties=""Excel 12.0;HDR=NO;IMEX=1"";")
dtTimes = New DataTable
Dim sqlstrTimes As String = "SELECT [F1] " & "FROM [SheetH$];"
Try
Dim MyCommandHistory As New OleDb.OleDbDataAdapter(sqlstrTimes , MyConnection)
MyCommandHistory.Fill(dtTimes)
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK
, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
Finally
MyConnection.Close()
End Try
dtTimes.Rows[0].Delete()