Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Updated 26-Feb-19 20:41pm

Here should be the syntax to return in between two numbers

VB
MResultsDV.RowFilter = "Handicap >=" & GlobalVariables.DivNo & " AND Handicap <=" & HighHandi
 
Share this answer
 
Comments
Maciej Los 27-Feb-19 2:41am    
5ed!
Bryian Tan 3-Mar-19 23:33pm    
Thanks :)
Dave the Golfer 27-Feb-19 13:40pm    
Thanks the change works
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:

VB
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.
 
Share this answer
 
Comments
Dave the Golfer 27-Feb-19 13:40pm    
Tried these links earlier but could not fathom the syntax. Thanks for the help.
Maciej Los 27-Feb-19 14:07pm    
You're very welcome.
If my asnwer was helpful, please accept it as a solution (green button).

Cheers
Maciej

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900