Click here to Skip to main content
15,747,766 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi All,

In databse table i have data this format in single sigle column -

This is test<br />
Question<br />
for<br />

when we write csv file the it should be in same cell and same like this
but it is going in other cell after each roe end.

if i do this as This is test<br />Question<br />for<br />Elearning

It writing fine in same cell. But I am entering data through ckeditor so we need press some time enter so data goes in multiple lines.
Updated 7-Mar-13 22:29pm

What you have to understand is that there is no cell in a .csv file. It is just a text file with specific fields/records separators (tabulations, commas, semicolons, carriage return...).

Thus storing a field with a line break is not possible 'as is' in a .csv file.

So, to be able to store your value corectly, you need to get rid of CR-LF in your data.

This could be achieved with the following code, for example :

// Here I assume you got the value from database into the <var>columnValue</var> variable.
columnValue = columnValue.Replace(Environment.NewLine, string.Empty);

Here we replace the new-line characters with a blank one, actually suppressing the line break. But you could replace by another character, if you want to be able to know which line breaks were removed.

Hope this helps.
Share this answer
rummer 12-Mar-13 1:45am    
Thanx a lot....
If you are talking about storing a line break inside a field in a csv file, you can try using a text delimiter like double quotes.
"Col1", "Col2", "Col3....
.....col3 continued in next line", "Col4", "Col5"
Share this answer

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