Domanda

I have a c# program that calls a SQL Stored proc, and passes some strings to it, e.g.

string str1 = "Some String 1";
string str1 = "Some String 2";
using (var command = new SqlCommand(MySP, conn)
        {
            CommandType = CommandType.StoredProcedure
        }
        )
{
    command.Parameters.AddWithValue("@Par1", str1);
    command.Parameters.AddWithValue("@Par2", str2);
    conn.Open();
    command.ExecuteNonQuery();
    conn.Close();
}

Now I would like to add a carriage return into str1.
But adding it like default (str1 = "Some \r\n string";) does not send the carriage return to SQL, but it sends the full string with the escape characters.

How else can I achieve this?

È stato utile?

Soluzione

Try using Environment.NewLine:

string str1 = "Some" + Environment.NewLine + "String";
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top