Search code examples
c#asp.netvb.netvisual-studiooledb

Quote within a .CSV data field


Here is my current connection string:

string connString = String.Format(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=""{0}"";Extended Properties=""text;HDR=NO;FMT=Delimited\""",Path.GetDirectoryName(csv_file_path));

This works fine except I have a few lines of code as follows:

"jon","smith","ohio"
"tom","jones","indiana"
"mary","baker "mills","florida

The last line has quotes within the field and the field is ending before "mills". Does anyone have a connection string that can accommodate a quote within a data field?

Thanks!


Solution

  • while fixing your source is the most correct answer, I suppose if you really want you can use var myStr = originalStr.replace(@"""",@""""""); this would escape all instances of the quote character.

    again, if possible, fix the data.