Kuttan Sujith
Kuttan Sujith

Reputation: 7979

How to insert new line to nvarchar using c# code

I have a table with a field ,description nvarchar(200).

I am inserting string with a lot of lines.

When I take quick watch over the string in visual studio, I can see the string splited over mutile lines as i expected.

line1
line2
line3

But when I insert to database using a stored procedure,all "\n\r" beomes just spaces. When I read from the databse there is no "\n\r"

what can i do?

Upvotes: 3

Views: 7505

Answers (4)

Akram Shahda
Akram Shahda

Reputation: 14771

Use CHAR(13)

Refer to: CHAR

Upvotes: 1

moi_meme
moi_meme

Reputation: 9318

its best to use System.Environment.NewLine

Upvotes: 0

Daniel A. White
Daniel A. White

Reputation: 190907

It should be stored just fine. When you look through SSMS, it removes the newlines for readability in its grid.

Upvotes: 14

Homam
Homam

Reputation: 23841

From this answer

char(13) is CR. For DOS-/Windows-style CRLF linebreaks, you want char(13)+char(10), like:

'This is line 1.' + CHAR(13)+CHAR(10) + 'This is line 2.'

Upvotes: 2

Related Questions