preety
preety

Reputation: 1066

Newline in SQL Server

Can anybody tell me how to save newline in database and also retrieve it in a same manner using asp.net.

Upvotes: 0

Views: 1963

Answers (5)

andrew pate
andrew pate

Reputation: 4307

If your looking at the DB data in sql server management studio (SSMS) then if you view the result as Query >> Results To >> results to grid

resultstogridmenu

That will strip the newlines as it puts the response in the grid, but if you choose Results To Text instead you can see they were persisted properly.

Newline characters disappearing in SQL Server

Upvotes: 0

Jamie
Jamie

Reputation: 1044

You want to use FormView to submit to a database?

http://sfvt.wordpress.com/2010/09/06/asp-net-tutorial-formview-insert-to-database/

Upvotes: 0

gbn
gbn

Reputation: 432672

SQL Server does no processing at all to data sent in. If you send this

aaa
bbb

ccc

Then this is exactly what is stored, complete with characters 13 and 10

If you are having problems, then it's likely chars 13 and 10 do not get into SQL Server or the page is removing them because they are suppressed whitespace in HTML.

To summarise, the problem is almost certain not to be with SQL Server

Upvotes: 6

Sidharth Panwar
Sidharth Panwar

Reputation: 4654

You can use System.Environment.NewLine in .Net to save the newline. If you simply press enter I think SQL saves it as \r\n.

Upvotes: 2

Gaurav Srivastava
Gaurav Srivastava

Reputation: 363

you can try \r\n or \n

Upvotes: 0

Related Questions