How to add a CR LF on SQL Server field and show as a new line in C# textbox

Posted on 2009-12-20
Medium Priority
Last Modified: 2013-12-17
I need to show in C# windows forms , in a multiline textbox I need to show the CR + LF that is stored in field.

In SQL Server I added the lines by doing the following
Update Table1 Set
COmment = comment + ' ' + char(13) + char(10) + @Comment

However when I view it in the C# , it becomes one line, what do I have to do to make it work?

Any help will be great.

Question by:hongning2009
LVL 19

Expert Comment

ID: 26092546

If you are just displaying this in GUI you should use

Update Table1 Set
COmment = comment + '\r\n'  + @Comment

Open in new window

LVL 11

Accepted Solution

lenordiste earned 2000 total points
ID: 26092678
\r\n is exactly the same thing as char(13) and char(10) which is exactly the same thing as Environment.NewLine on a windows plateform...

Your solution looks fine Noel and there's no reason why your textbox doesn't show multiple lines. Are you sure you set "TextBox.MultiLine = True" correctly? Maybe you should inspect what your sql select returns and make sure you do have those CRLF chars in the result.
LVL 10

Expert Comment

ID: 26094785
It should be '\r\n' along with TextBox.MultiLine = True

Expert Comment

ID: 26095320
Use "\n" to move on next line or for carriage return.

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

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

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

807 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