3

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?

Kuttan Sujith
  • 7,811
  • 18
  • 63
  • 92

4 Answers4

14

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

Daniel A. White
  • 181,601
  • 45
  • 354
  • 430
2

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.'
Community
  • 1
  • 1
Homam
  • 22,486
  • 32
  • 107
  • 183
1

Use CHAR(13)

Refer to: CHAR

Akram Shahda
  • 14,295
  • 4
  • 43
  • 64
0

its best to use System.Environment.NewLine

moi_meme
  • 8,748
  • 4
  • 45
  • 61