The error is:
The Microsoft Jet database engine could not find the object `FileName.csv` Make sure the object exists and that you spell its name and the path name correctly.
I am using vb.net to determine the path and name so that isn't the issue.
My code:
Public Sub ConvertCSV()
Dim DirectoryPath, FileName, FileNameAndPath As String
Dim openFileDialog1 As New OpenFileDialog()
openFileDialog1.InitialDirectory = "C:\Documents and Settings\ADMIN\Desktop"
openFileDialog1.Filter = ".csv files (*.csv)|*.csv"
openFileDialog1.FilterIndex = 2
openFileDialog1.RestoreDirectory = True
If openFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
FileNameAndPath = openFileDialog1.FileName
Dim fi As New IO.FileInfo(FileNameAndPath)
DirectoryPath = fi.DirectoryName
FileName = System.IO.Path.GetFileName(FileNameAndPath)
'Note that the folder is specified in the connection string,
'not the file. That's specified in the SELECT query, later.
Dim connString As String = "Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=" _
& DirectoryPath & ";Extended Properties=""Text;HDR=No;FMT=Delimited"""
Dim conn As New Odbc.OdbcConnection(connString)
'Open a data adapter, specifying the file name to load
Dim da As New Odbc.OdbcDataAdapter("SELECT * FROM [" & FileName & "]", conn)
'Then fill a data table, which can be bound to a grid
Dim dt As New DataTable
da.Fill(dt)
'grdCSVData.DataSource = dt
End If
End Sub
I have read Reading CSV into using OLEDB and I am not using a 64bit system, cpu, or visual studio.
How to read a CSV file into a .NET Datatable doesn't work. I don't want to introduce anything custom. That's why I am updating this project.
http://social.msdn.microsoft.com/Forums/en-US/4f860035-e081-44b9-a08c-b3911f682975/problem-using-odbcdatareader-to-read-from-a-csv-file says I should only use the filename, not the entire path in the SQL statement. That's what I am doing.
I've seen this code in some shape or form all over the place Visual Basic How do I read a CSV file and display the values in a datagrid?
Edit: Can I learn anything at the line Dim da As New Odbc.OdbcDataAdapter
from the mouse over properties like if the connection failed or what information should be in the various fields?