我有
CmdString = "insert into Team_table (name1, name2, result1, result2) (select t1.name,t2.name,NULL,NULL from teams t2 cross join teams t1)";
当按下输入时将其分为2列,如
CmdString = "insert into Team_table (name1, name2, result1, result2)
(select t1.name,t2.name,NULL,NULL from teams t2 cross join teams t1)";
错误出现
我该如何解决?
答案 0 :(得分: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)";
答案 1 :(得分: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#语句,并且它期望您关闭前一个字符串并使用;
"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)";
答案 2 :(得分:3)
喜欢这个。
CmdString = "insert into Team_table (name1, name2, result1, result2)" +
"(select t1.name,t2.name,NULL,NULL from teams t2 cross join teams t1)";