문제

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?

도움이 되었습니까?

해결책 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)";

다른 팁

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)";
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top