Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2004-04-26
4
Medium Priority
?
2,292 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 200 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

926 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