-2

我有

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

当我通过 presssiin 将它分成 2 列时,输入就像

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

出现错误

我该如何解决?

4

3 回答 3

5

尝试关注

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

或者

CmdString = @"insert into Team_table (name1, name2, result1, result2) 
(select t1.name,t2.name,NULL,NULL from teams t2 cross join teams t1)";
于 2013-11-04T18:25:21.543 回答
4

@在字符串前面使用符号,然后您可以在多行上断开字符串

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

您收到错误的原因是因为编译器将新行视为新的 C# 语句,并且希望您关闭前一个字符串并使用终止语句;

编辑:正如@Servy指出的那样,将其设为逐字字符串(带有@)将导致换行符成为字符串的一部分。所以你的字符串会是这样的:

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

如果您不想要换行符并且想要在多行上拆分字符串,那么您必须在每行上定义一个字符串并使用连接,例如:

string CmdString = 
    "insert into Team_table (name1, name2, result1, result2) " + 
    "(select t1.name,t2.name,NULL,NULL from teams t2 cross join teams t1)";
于 2013-11-04T18:25:08.307 回答
3

像这样。

    CmdString = "insert into Team_table (name1, name2, result1, result2)" + 
        "(select t1.name,t2.name,NULL,NULL from teams t2 cross join teams t1)";
于 2013-11-04T18:24:56.997 回答