Click here to Skip to main content
15,881,380 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have to read data from CSV and unfortunately data of one column have comma (",") in it
Posted
Comments
CHill60 17-Jun-15 6:45am    
That is unfortunate. Have you tried defining the string delimiter character - are the strings surrounded by double-quotes for example?
If not, and they are not defined by any other character, then your source data is incorrect.

1 solution

Whatever generates the CSV file needs to wrap the fields in quotes

"field 1", "field 2", "this, that"

then your code needs to treat only commas outside of quote pairs as being the separators so that it knows "this, that" is a single field and not two. There are various libraries out there that will already do this for you if you google "c# csv parser"

C# - Light and Fast CSV Parser[^]
 
Share this answer
 
Comments
deepakdynamite 17-Jun-15 6:55am    
Thanks for you your solution. we are using c# code under script task to do this. It takes more time then expected as number of records\rows in file are more than 1 lacs and some times goes more than 1 million.
CHill60 17-Jun-15 6:59am    
Or just define the text qualifier in the SSIS package?
F-ES Sitecore 17-Jun-15 7:06am    
Yeah, my bad, didn't see this was as part of SSIS. The CSV file is still going to need the quote wrappers though.
deepakdynamite 18-Jun-15 0:34am    
I used "," (Entire ",") as column delimiter and it works fine for now but there may be other consequences with other columns...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900