I have excel csv file with a dot in file name. (This is the industry naming convention, so I cannot change it.) I am trying to read all data using OLEDB. If I remove the dot from file name, my command works. If not it says invalid object. How to ignore/resolve dot in file name ?
file name : ABC Test bank Trail Feb 2014 $ 18083.65.csv
my code:
Public Function GetAllData(ByVal FileName As String) As DataTable
Try
Dim dt As New DataTable
Using con As New OleDbConnection With {.ConnectionString = String.Format(ConnectionNoHeader, Path.GetDirectoryName(FileName))}
cn.Open()
Dim SQLAdapter As OleDbDataAdapter = New OleDbDataAdapter()
Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM [" + Path.GetFileName(FileName) + "]", con)
SQLAdapter.SelectCommand = cmd
SQLAdapter.Fill(dt)
End Using
Return dt
Catch
Return Nothing
End Try
End Function
http://social.msdn.microsoft.com/Forums/en-US/22302a07-d599-46c5-be19-6164156e7762/reading-a-csv-file-with-embedded-periods-in-the-file-name-using-oledbcommand?forum=adodotnetdataproviders suggests using the API call GetShortPathName to use the old MS-DOS 8.3 version of the filename.