天涯一飘絮

导航

 

DataView的RowFilter里面遇到的特殊字符要用"[]"括起来,单引号要换成"''"。

LIKE关键字进行过滤时,如果碰到特殊字符包含:"[","]","%","*","'" 解决的方法如下:

dv.RowFilter = "[Code] like '%条件字符串%'";

过滤条件字符处理后,内容如下:

string rowFilter=条件字符串;

rowFilter=rowFilter.Replace("[", "[[ ")
                .Replace("]", " ]]")
                .Replace("*", "[*]")
                .Replace("%", "[%]")
                .Replace("[[ ", "[[]")
                .Replace(" ]]", "[]]")
                .Replace("\'", "''");

dv.RowFilter = "[Code] like '%" + rowFilter+ "%'";

posted on 2011-01-09 00:55  冰云  阅读(322)  评论(0编辑  收藏  举报