Question

I have

CmdString = "insert into Team_table (name1, name2, result1, result2) (select t1.name,t2.name,NULL,NULL from teams t2 cross join teams t1)";

Whene I divide it in 2 columns by presssiin enter like

CmdString = "insert into Team_table (name1, name2, result1, result2) 
(select t1.name,t2.name,NULL,NULL from teams t2 cross join teams t1)";

errore appears

How can I solve that?

Was it helpful?

Solution 2

Use @ symbol in front of the string , then you can break the string on multiple lines

string CmdString = @"insert into Team_table (name1, name2, result1, result2) 
                (select t1.name,t2.name,NULL,NULL from teams t2 cross join teams t1)";

The reason you are getting the error is because the compiler is considering new line as a new C# statement, and it is expecting you to close the previous string and terminate the statement using ;

EDIT: As @Servy has pointed out, making it a verbatim string (with @) would result in the new line character to be part of string. So your string would be something like:

"insert into Team_table (name1, name2, result1, result2) \r\n (select t1.name,t2.name,NULL,NULL from teams t2 cross join teams t1)"

If you don't want the line break and want to split string on multiple lines, then you have to define a single string on each line and use concatenation like:

string CmdString = 
    "insert into Team_table (name1, name2, result1, result2) " + 
    "(select t1.name,t2.name,NULL,NULL from teams t2 cross join teams t1)";

OTHER TIPS

Try following

CmdString = "insert into Team_table (name1, name2, result1, result2)" + 
" (select t1.name,t2.name,NULL,NULL from teams t2 cross join teams t1)";

or

CmdString = @"insert into Team_table (name1, name2, result1, result2) 
(select t1.name,t2.name,NULL,NULL from teams t2 cross join teams t1)";

Like this.

    CmdString = "insert into Team_table (name1, name2, result1, result2)" + 
        "(select t1.name,t2.name,NULL,NULL from teams t2 cross join teams t1)";
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top