Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the correct syntax in c# to create a line break in the middle of a mysql string? [duplicate]

Tags:

c#

mysql

Possible Duplicate:
Multiline String Literal in C#

I'm probably not asking the right questions of Google to find my answer. I just want to keep my code neat without having a really long string on one line. I want to move to the next line without breaking the string.

cmd.CommandText = "UPDATE players SET firstname = CASE id WHEN 1 THEN 'Jamie' WHEN 2 THEN 'Steve' WHEN 3 THEN 'Paula' END WHERE id IN (1,2,3)";

For example, I would like to break this into two lines without affecting the string. All help would be appreciated.

like image 300
webby68 Avatar asked Sep 28 '12 17:09

webby68


2 Answers

I suspect what you want is to use the @ for verbatim string literals; the advantage of verbatim strings is that escape sequences are not processed, and that they can span multiple lines.

cmd.CommandText = @"UPDATE players 
                    SET firstname = 
                      CASE id 
                        WHEN 1 THEN 'Jamie' 
                        WHEN 2 THEN 'Steve' 
                        WHEN 3 THEN 'Paula' 
                      END 
                    WHERE id IN (1,2,3)";
like image 183
Joachim Isaksson Avatar answered Sep 19 '22 01:09

Joachim Isaksson


Use @ symbol before string. It will say to compiler that string is multiline.

cmd.CommandText = @"UPDATE players 
                    SET firstname = CASE id 
                        WHEN 1 THEN 'Jamie' 
                        WHEN 2 THEN 'Steve' 
                        WHEN 3 THEN 'Paula' 
                        END WHERE id IN (1,2,3)";
like image 22
Dmytro Avatar answered Sep 19 '22 01:09

Dmytro