2014-02-08 2 views
3

나는 다음과 같은 코드가 있습니다! "에릭"DataTable 식 토큰 '!'을 해석 할 수 없습니다.

//myDataTable has the following collumns: UserName, Birthday and email. 
string name = "eric!"; 
string expression = "UserName = " + name; 
DataRow[] result = myDataTable.Select(expression); 

내가 이름을 가진 모든 행을 선택합니다을.
"!" 다음과 같은 오류가 발생합니다 :

Cannot interpret token "!".

토큰이있는 모든 행을 어떻게 선택합니까?
은 값 주위

답변

4

name'' 사이에 사용해야합니다. 처럼; 작은 따옴표없이

string name = "'eric!'"; 

, 당신의 DataTable.Select 방법은 !운영자이며이 유효한 연산자로 DataColumn.Expression property에서 허용되지 않습니다 생각한다.

문서;

User-Defined Values

User-defined values may be used within expressions to be compared with column values. String values should be enclosed within single quotation marks.

2

당신이 누락 된 따옴표 (' ') (난 정말이 "!"표현에 나는이 (가) .SQL 파일에서 사용자 이름을 추출하기 때문에 필요)

이없이 필터 연산자를 쓰기
string name = "eric!"; 
string expression = "UserName = '" + name+'"; 
DataRow[] result = myDataTable.Select(expression); 

따옴표 및 ! 함께 !연산자가 아닌 것으로 간주됩니다 그 이유는 오류가 있습니다.

관련 문제