1

I encounter an error ('\csvFile.csv' is not a correct path.Check if the path name is correct)while trying to load csv file to datagridview using OleDB connection:

        MyConnection = new System.Data.OleDb.OleDbConnection("Provider = Microsoft.Jet.OLEDB.4.0; Data Source = '\\csvFile.csv'; Extended Properties = \"text;HDR=Yes;FMT=Delimited\"");

What is correct format of this connection string?File is located within project's folder.

In different window I'm loading the same csv file using StreamReader. It works fine.Would that influence the OleDB connection?

Aga
  • 113
  • 1
  • 8
  • Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\txtFilesFolder\; Extended Properties="text;HDR=Yes;FMT=Delimited" .... (found that with google) – nabuchodonossor Oct 25 '18 at 13:21
  • @nabuchodonossor Of course I did my research before asking this question..Unfortunately this solution didn't work neither. – Aga Oct 25 '18 at 13:29
  • "\csvFile.csv": do you have your csv in your root directory? – nabuchodonossor Oct 25 '18 at 14:43
  • @nabuchodonossor yes – Aga Oct 25 '18 at 15:03
  • [Parsing CSV using OleDb](https://stackoverflow.com/questions/6813607/parsing-csv-using-oledb-using-c-sharp?answertab=active#tab-top) – Jimi Oct 25 '18 at 17:57
  • Forgot to mention. If you want to a *catalog* type of access, you need to use a `schema.ini` file: [Schema.ini File (Text File Driver)](https://learn.microsoft.com/en-us/sql/odbc/microsoft/schema-ini-file-text-file-driver?view=sql-server-2017) – Jimi Oct 25 '18 at 19:29
  • Thanks @Jimi.Now I'm getting error:Wrong parameter used.I guess it's better if I start all over again. – Aga Oct 26 '18 at 08:51
  • Start from ditching this => `'\\csvFile.csv'` and using a string variable in a `string.Format()` or `$"{ }"` an interpolated construct. `The Extended Properties` part is also malformed. – Jimi Oct 26 '18 at 13:03

0 Answers0