Solved

how to store a multiline textstring in a sql server db?

Posted on 2004-04-26
4
2,116 Views
Last Modified: 2008-03-17
I have a text string, retrieved from a multiline textbox (c#.net). In the textbox I have used this input to test:

This
Is a
Test

When I debug the program, I can see that the string variable containg the text looks like this when it is used in the Insert statement:

"This\r\nIs a\r\nTest"

The \r\n represents linebreak.
But in the database only "This" is stored. "Is a Test" is not stored. It looks like sql server interprets the \r\n as an escape sequence or something??? The type in the database is nvarchar. Anybody have an idea how to store the whole string (with the linespaces, so that the linespaces are still there when I retrive the string from the db)????

Regards, Anders
0
Comment
Question by:astensland
  • 2
  • 2
4 Comments
 
LVL 26

Expert Comment

by:Hilaire
ID: 10916541
SQL Server has no problem to store this kind of string.
\r\n is not an escape sequence.

I guess the problem is somewhere else, eg the debug is writing the retrived results in a single-line control
0
 

Author Comment

by:astensland
ID: 10916797
This is how the insert statement looks like, before it is executed... I don't think the problem lies in the control. I have not tried to retrieve the data to a control yet, I have just checked directly in the database... And in the database, only the word "this" is stored... very strange...

"INSERT INTO Beskrivelse_av_hendelse VALUES(201, 1, 25, '4.26.2004 11:30:04', 'this\r\nis\r\ns\r\ntest')"

Anyone have an idea??
0
 
LVL 26

Accepted Solution

by:
Hilaire earned 50 total points
ID: 10916877
>>I have just checked directly in the database<<

I guess you have checked that using Enterprise Manager-->Tables--> return all rows
EM's grids have single lined cells and don't display multiline content

Use Query analyser instead
select your DB/catalog from the drop-down
type
select * from Beskrivelse_av_hendelse
press F5

HTH

Hilaire
0
 

Author Comment

by:astensland
ID: 10916974
Thanks alot Hilaire!!! You were absolutely right.
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now