Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2004-04-26
4
Medium Priority
?
2,253 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: 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

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

722 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