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

Posted on 2009-12-20
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


    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

    \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

    It should be '\r\n' along with TextBox.MultiLine = True
    LVL 7

    Expert Comment

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

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
    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 discusses moving either the default database or any database to a new volume.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    755 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

    17 Experts available now in Live!

    Get 1:1 Help Now