我尝试对两个DataView进行排序,在dgtest1中,除了包含Typeid != 25的数据外,我还试图在dgtest2中只显示Typeid == 25中的数据。
当我跨过代码时,我会抛出一个错误
“不能解释标记'!‘在第6位置”。
有人能告诉我如何正确使用字符串行筛选器吗?
参数为(数据表、字符串RowFilter、字符串排序、DataViewRowState)
dgtest1.ItemsSource = new DataView(dttest1, "Typeid!= 25", "", DataViewRowState.CurrentRows);
dgtest2.ItemsSource = new DataView(dttest1, "Typeid == 25", "", DataViewRowState.CurrentRows);发布于 2013-09-03 19:35:36
第一个Dataview构造函数中的RowFilter表达式使用的正确语法是
dgtest1.ItemsSource = new DataView(dttest1, "Typeid <> 25", "", DataViewRowState.CurrentRows);
^^ 在第二部分中,您需要使用
dgtest2.ItemsSource = new DataView(dttest1, "Typeid = 25", "", DataViewRowState.CurrentRows);用于RowFilter构造函数中的DataView参数的语法与用于DataColumn的属性表达式的语法相同,与C#的相等运算符不同。
在下面的评论之后,编辑。如果Typeid是文本数据类型的数据库字段,则需要将RowFilter中使用的值括在单引号之间。
dgtest1.ItemsSource = new DataView(dttest1, "Typeid <> '25'", "", DataViewRowState.CurrentRows);
dgtest2.ItemsSource = new DataView(dttest1, "Typeid = '25'", "", DataViewRowState.CurrentRows);然而,这似乎有点奇怪。如果Typeid字段包含数字,则应将其定义为数字数据类型。
https://stackoverflow.com/questions/18600104
复制相似问题