Based on the code posted by the OP here (which theoretically should work for me with the well-formatted test file I've got), I'm trying this to assign the contents of a CSV file to a DataGridView:
string conStr = @"Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=" + selectedFile + ";Extensions=csv,txt";
OdbcConnection conn = new OdbcConnection(conStr);
OdbcDataAdapter da = new OdbcDataAdapter("Select * from [" + Path.GetFileName(selectedFile) + "]", conn);
DataTable dt = new DataTable(selectedFile);
da.Fill(dt);
dataGridViewFileContents.DataSource = dt;
da.Dispose();
conn.Close();
conn.Dispose();
When running through my test scenario, the value of selectedFile is C:\PersianUtil\persianUtilOutput.txt and the value of conStr is Driver={Microsoft Text Driver (.txt; .csv)};Dbq=C:\PersianUtil\persianUtilOutput.txt;Extensions=csv,txt
But on the "da.Fill(dt);" line I'm getting:
System.Data.Odbc.OdbcException was unhandled
HResult=-2146232009
Message=ERROR [HY024] [Microsoft][ODBC Text Driver] '(unknown)' is not a valid path. Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides.
ERROR [01000] [Microsoft][ODBC Text Driver]General Warning Unable to open registry key 'Temporary
(volatile) Jet DSN for process 0x26d4 Thread 0x11d8 DBC 0x8649fd4 Text'.
ERROR [IM006] [Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr failed
ERROR [01000] [Microsoft][ODBC Text Driver]General Warning Unable to open registry key 'Temporary
(volatile) Jet DSN for process 0x26d4 Thread 0x11d8 DBC 0x8649fd4 Text'.
ERROR [HY024] [Microsoft][ODBC Text Driver] '(unknown)' is not a valid path. . . .
What am I doing wrong or failing to do here?
If there's a better way to do this / alternate methodology, I'm open to that, too.