Solved

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

Posted on 2004-04-26
4
2,177 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 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
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.

752 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