Sql – Returning non-printable sybol (enter) to SQL Server from C# via CLR


I have the following CLR function:

    public static SqlString PrintText(SqlString text)
        // Put your code here
        return new SqlString(text.Value);

And I want to get an enter symbol when passing


to it. But insteat I get


Could you please tell me what's wrong with this code.

Thank you.

Best Solution

In T-SQL you don't write a line break as \r\n. Instead you just use a line break:

is a
in SQL
line breaks'

If you pass a string with \r\n to the C# code, nothing magical happens, it doesn't automatically get converted. The backslash character is just a character like any other. It's when you use the backslash in a literal string in the code that the compiler uses it as an escape code, and puts the control characters in the actual string.