0

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!

Community
  • 1
  • 1
John
  • 15,990
  • 10
  • 70
  • 110

2 Answers2

1

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
  • 344,730
  • 71
  • 640
  • 635
  • Hah ... OK, only the first line shows up in Access 2007, but they're all there. Thanks! – John Jul 13 '09 at 18:43
0

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
  • 15,990
  • 10
  • 70
  • 110