Solved

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

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
execute a MS SQL script as a schedule SQL job 72 101
MS SQL export CSV & schedule It 9 44
SQL server 2008 SP4 29 35
Join vs where 2 0
Performance is the key factor for any successful data integration project, knowing the type of transformation that you’re using is the first step on optimizing the SSIS flow performance, by utilizing the correct transformation or the design alternat…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
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.

746 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

10 Experts available now in Live!

Get 1:1 Help Now