DataView的RowFilter里面遇到的特殊字符要用"[]"括起来,单引号要换成"''"。
LIKE关键字进行过滤时,如果碰到特殊字符包含:"[","]","%","*","'" 解决的方法如下:
dv.RowFilter =
"[Code] like '%条件字符串%'"
;
过滤条件字符处理后,内容如下:
string rowFilter=条件字符串;
rowFilter=rowFilter.Replace("[", "[[ ")
.Replace("]", " ]]")
.Replace("*", "[*]")
.Replace("%", "[%]")
.Replace("[[ ", "[[]")
.Replace(" ]]", "[]]")
.Replace("\'", "''");
dv.RowFilter =
"[Code] like
'%"
+
rowFilter+
"%'"
;