S/B EZ: Losing Carriage Returns and Line Feeds in SQL Server

Hopefully this isn't too difficult, but after searching I haven't really found a solution.

My VB.NET Windows App stores information that is input into a rich text box (a text box would be fine too) into a field of an SQL Server database.  The important thing is KEEPING carriage returns and line feeds.  When I pull the data back out, Carriage Returns and Line Feeds are lost.  E.g.

Hello

How Are you

Have you been alright.

Comes back as:

HelloHow Are youHave you been alright.

So I need to preserve the CR's and LF's.  I've read articles where they suggest replacing the CR's and LF's with the <br /> tag, but this isn't a web app, and doesn't appear to work for an Windows application.

I tried configuring the SQL field as varchar(), nvarchar(), and ntext, but there's no difference in the result.

Any help?
LVL 2
kmoloneyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dqmqCommented:
I doubt you are saving CRLF in the first place.  Add some diagnostic code to your VB app to confirm the value of the field before you save it.  I'm speculating you'll see something besides CRFL at the line breaks.

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Priest04Commented:
You need to save RTF property of the RichTextBox, and then later load data from database to RTF property again, and all will work well.

Goran
0
Jeff CertainCommented:
In keeping with what dgmg said... put a breakpoint where you're retrieving the text. If you have CR/LF there, they will show up as boxes (non-printable characters) in the text string.
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

kmoloneyAuthor Commented:
SORRY I've been so long in getting back to this question.  Muy busy these days.

Okay, well, when retreiving the rtf property, I'm getting something like the following:

{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 Microsoft Sans Serif;}}
\viewkind4\uc1\pard\f0\fs17 Now is the time for all men to come to aid of their country.\par
\par
However, I have some reservations.\par
\par
I am a coward.\par
\par
Thank you---\par
\par
Kevin\par
}

Which I imagine could be parsed...however...

NOW -- for a bit more intriguing problem...turns out the application DOES have to be a web app, which means...no rich text box control.  So if I'm just using the textbox control (multiline), all CR's and LF's are being removed when I retrieve the info using the .text property of the text box.

Grrrrrrr....
0
kmoloneyAuthor Commented:
OK, I'm half way there --

Converting the the text to have CRLF's isn't that bad; I just do a replace before I save the text in the textbox:

e.g., strVar = TextBox1.Text.Replace(Environment.Newline,Microsoft.VisualBasic.VbCrLf)

That seems to store it okay in SQL.  Now only problem remaining is getting that out to display in web-based controls, like a repeater.  Replacing with "<BR />" doesn't seem to work.
0
kmoloneyAuthor Commented:
It turned out that my question wasn't properly phrased, so I awarded points equally.  The issue is going between VB or VS Studio 2005 controls bound to SQL Server.  Multilines DO store crlf's as characters (Microsoft.VisualBasic.VBCRLF), and that the basic approach to solve the problem was in my last comment dated 5/3/2007.  However, flipping back and forth between display and input states of a one of the VS2005 databound controls (e.g., a formview) should (IMHO) take into account the transition ahead of time.

Manually replacing <BR />'s with Microsoft.VisualBasic.vbCrLf's, and vice versa, in any situation where a view might change from edit to view, is silly.  The control should recognize the context in which it is being viewed in, and developer shouldn't have to piddle with details like this.

This question is in no way solved.  I'll have to post a new one specific to the VS controls I'm interested in.

Thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2005

From novice to tech pro — start learning today.