views:

80

answers:

2

EDIT: Accepted answer points out what my issue was. I added another answer which shows an even easier way.

I have a multiline textbox from which I create a single string:

    Dim wholeThing As String
    Dim line as String 
    For Each line In txtMultiline.Lines
        wholeThing = wholeThing & line & Environment.Newline
    Next

What I'd like to do is write this to a DB as-is by adding wholeThing as a parameter using to SqlCommand.Parameters.AddWithValue, but all of my painstakingly-inserted newlines go away (or appear to).

I saw this and was hoping I didn't need to concern myself with CHAR(nnn) SQL stuff.

Any suggestions? Thanks!

+1  A: 

What do you mean when you say "appears to"? A newline character can be easily stored in an nvarchar field. What tools are you using to verify the results of your actions?

Andrew Hare
Point taken ... I'll check ...
John at CashCommons
Hah ... OK, only the first line shows up in Access 2007, but they're all there. Thanks!
John at CashCommons
Very cool - no problem!
Andrew Hare
A: 

It's even easier than this. As per the discussion in the accepted answer, I wasn't seeing all of the lines in my view. Putting up a messagebox showed everything.

What's more, I don't need to take things line by line:

wholeThing = txtMultiline.Text

works, too, and it keeps all of the line breaks.

John at CashCommons