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
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…