I am trying to build a string that includes a newline character and is getting the weirdest result. This string is going to be stored in a SQL database to be later used as part of an email. My code is the following:
Dim strBody As String = "Andy," & Environment.NewLine
When I inspect the value of strBody
during a debugging session, it is the following:
"Andy," & vbCrlf
I am obviously expecting is to be more like:
"Andy,"
Knowing that what is after the ,
is a hidden character.
Ultimately, the problem is... when I include strBody
as part of my SQL insert
statement, it literally shows up as the following within my SQL insert
statement:
'Andy," & vbCrLf & "'
I was using this code yesterday and it worked fine. I am using similar code within another function of the same asp.net project and it works fine. I have tried using +
instead of &
, I have tried to use vbCrLf instead of Environment.NewLine
, I have tried using stringbuilder
, I have tried using string.concat
. All with the same results where the & vbCrLf
is included in strBody
.
Is there a setting that I accidentally changed?
I know this is a weird one... Any help is greatly appreciated.