如何使用两个过滤器过滤数据视图 [英] How to filter a dataview with two filters
问题描述
我有一个包含高尔夫比赛结果的数据视图。我希望根据让分将结果分成三个部分
我有两个全局变量:
GlobalVariables.DivNo
和
GlobalVariables.DivNo2
从csv文件中定义为16和20
对于第一个分部,我的代码令人满意,是
Dim LowHandi As String = GlobalVariables.DivNo + 1
MResultsDV.RowFilter =Handicap< &安培; LowHandi
第三个分区代码,也能令人满意地工作,是
MResultsDV.RowFilter =让分> &安培; GlobalVariables.DivNo2
但是我的代码需要过滤17到20之间的差点结果不起作用。
什么我试过了:
我的第一次尝试是
Dim HighHandi As String = GlobalVariables.DivNo2 + 1
MResultsDV.RowFilter =让分> &安培; GlobalVariables.DivNo
MResultsDV.RowFilter =Handicap< &安培; HighHandi
然而,最后一个过滤器写了第一个。
所以,我试过
Dim HighHandi As String = GlobalVariables .DivNo2 + 1
MResultsDV.RowFilter =让分> &安培; GlobalVariables.DivNo和Handicap< &安培; HighHandi
但出现以下错误;
System.InvalidCastException:'从字符串Handicap> 16转换为Long类型无效。'
然后我尝试了
Dim HighHandi As String = GlobalVariables.DivNo2 + 1
MResultsDV.RowFilter =Handicap> &安培; GlobalVariables.DivNo AndAlsoHandicap< &安培; HighHandi
但是出现了这个错误; System.InvalidCastException:'从字符串Handicap> 16转换为'Boolean'类型无效。'
我也试过
MResultsDV .RowFilter ='让分> &安培; GlobalVariables.DivNo'和'障碍< &安培;运行但不起作用的HighHandi'
这里应该是两个数字之间返回的语法
MResultsDV.RowFilter = 让分> = & GlobalVariables.DivNo& &Handicap< =& HighHandi
A DataView.RowFilter属性(System.Data)| Microsoft Docs [ ^ ]属性的工作方式与 DataColumn.Expression属性(System.Data)| Microsoft Docs [ ^ ]。
因此,您可以构建复杂的表达式,例如:
DataView11.RowFilter = ColumnName1 = 555 AND(ColumnName2 like'A *'OR ColumnName3比如'* A')
运算符:允许使用布尔AND,OR和NOT运算符进行连接。您可以使用括号将子句分组并强制优先。 AND运算符优先于其他运算符。例如:
(LastName ='Smith'或LastName ='Jones')AND FirstName ='John'
字符串运算符:要连接字符串,请使用+字符。 DataSet类的CaseSensitive属性的值确定字符串比较是否区分大小写。
请按照我提供的链接。
I have a dataview containing the results of a golf competition. I wish to split the results into three divisions based on "Handicap"
I have two Global Variables namely:
GlobalVariables.DivNo
and
GlobalVariables.DivNo2
which are defined from a csv file as 16 and 20
For the first Division my code, which works satisfactorily, is
Dim LowHandi As String = GlobalVariables.DivNo + 1 MResultsDV.RowFilter = "Handicap <" & LowHandi
the third Division code, which also works satisfactorily, is
MResultsDV.RowFilter = "Handicap >" & GlobalVariables.DivNo2
However my code which needs to filter out the results for handicaps between 17 and 20 does not work.
What I have tried:
My first try was
Dim HighHandi As String = GlobalVariables.DivNo2 + 1 MResultsDV.RowFilter = "Handicap >" & GlobalVariables.DivNo MResultsDV.RowFilter = "Handicap <" & HighHandi
However, the last filter over wrote the first.
So, I tried
Dim HighHandi As String = GlobalVariables.DivNo2 + 1 MResultsDV.RowFilter = "Handicap >" & GlobalVariables.DivNo And "Handicap <" & HighHandi
but got the following error;
System.InvalidCastException: 'Conversion from string "Handicap >16" to type 'Long' is not valid.'
I then tried
Dim HighHandi As String = GlobalVariables.DivNo2 + 1 MResultsDV.RowFilter = "Handicap >" & GlobalVariables.DivNo AndAlso "Handicap <" & HighHandi
but got this error; System.InvalidCastException: 'Conversion from string "Handicap >16" to type 'Boolean' is not valid.'
I also tried
MResultsDV.RowFilter = '"Handicap >" & GlobalVariables.DivNo' And '"Handicap <" & HighHandi'
which ran but did not work
Here should be the syntax to return in between two numbers
MResultsDV.RowFilter = "Handicap >=" & GlobalVariables.DivNo & " AND Handicap <=" & HighHandi
A DataView.RowFilter Property (System.Data) | Microsoft Docs[^] property works in the same manner as DataColumn.Expression Property (System.Data) | Microsoft Docs[^].
So, you can build complex expression, for example:
DataView11.RowFilter = "ColumnName1 = 555 AND (ColumnName2 Like 'A*' OR ColumnName3 Like '*A')"
Operators:Concatenation is allowed using Boolean AND, OR, and NOT operators. You can use parentheses to group clauses and force precedence. The AND operator has precedence over other operators. For example:
(LastName = 'Smith' OR LastName = 'Jones') AND FirstName = 'John'
String operators:To concatenate a string, use the + character. The value of the CaseSensitive property of the DataSet class determines whether string comparisons are case-sensitive.
Please, follow the links i've provided.
这篇关于如何使用两个过滤器过滤数据视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!