2013-11-04 3 views
-2

을 가지고 내가 가지고 내가; 예상 C#을 전송 및 큰 문자열 VS2012

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

errore 같이 입력 presssiin에 의해 2 열을

가 어떻게 그것을 해결할 수 있습니다 나타납니다 분할 Whene

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

?

+0

'errore가 표시됩니다. '오류는 ...? – tnw

답변

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)"; 

다음은 오류를 얻고있는 이유는 컴파일러가 새로운 새로운 라인을 고려하고 있기 때문이다에 문자열을 깰 수 @Servy는 그것을 그대로 문자열 (w을, 지적했듯이 : C는 # 문, 이전의 문자열을 닫고 ;

EDIT를 사용하여 문을 종료를 기대하고있다 ith @)은 줄 바꿈 문자가 문자열의 일부가되도록합니다. 그래서 문자열과 같이 될 것이다 : 당신은 줄 바꿈을 원하는 여러 줄에 문자열을 분할 할 수없는 경우

"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)"; 
+4

그러면 줄 바꿈은 문자열 자체에 있습니다. 그럴 수도 있고 그렇지 않을 수도 있습니다. – Servy

+2

+1 유일한 해결책으로, 나는'+'를 사용했을 것이다. – gleng

+1

@Servy T-SQL 문이기 때문에 줄 바꿈/공백에는 부작용이 없다고 생각합니다. –

3

이렇게하면됩니다.

CmdString = "insert into Team_table (name1, name2, result1, result2)" + 
     "(select t1.name,t2.name,NULL,NULL from teams t2 cross join teams t1)"; 
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)";