Search code examples
c#sqlformstext-formatting

Storing text in SQL with formatting (breaklines etc.)


I currently have

<textarea id="Commentary" rows="5" cols="40" runat="server"></textarea>

Then in the event

insertCommand.Parameters["@Commentary"].Value = "<pre>" + Commentary.Value + "</pre>";

If I entered into the HTML input box, for example

  • new line 1
  • new line 2
  • New line 3

It puts that into the SQL field as

 - new line 1  - new line 2  - new line 3

How do I keep things like line breaks? I will be displaying the data in a table, so I want to keep things such as line breaks.

Thanks,


Solution

  • It does not changes formatting. All required symbols are there. But if you are looking at it in MS Sql Server Management studio it won't show you formatting. At the same time you should be able to select it from database later and put on your page. And formatting will be kept.