Create correct Criteria Operator

977 Views Asked by At

Trying to create a Criteria.Parse operator when I have to convert the string field to an Int. Operation fails at the follwing:

Message=Parser error at line 0, character 15: syntax error; ("Convert.ToInt16{FAILED HERE}(awayML)>130")

Here is my code:

XPCollection collection = new XPCollection(session1, typeof(TodaysGame), CriteriaOperator.Parse("Convert.ToInt16(awayML)>130"));
int ct = collection.Count;

How do I form the Criteria using the Convert.ToInt16 function?

2

There are 2 best solutions below

2
Nikita K On BEST ANSWER

Criteria operators have their own syntax to convert string literals to int values. You need to use them instead of system Convert.ToInt function:

Function Description Example
ToInt(Value) Converts Value to an equivalent 32-bit signed integer. ToInt([Value])
ToLong(Value) Converts Value to an equivalent 64-bit signed integer. ToLong([Value])

You can check the full reference of DevExpress criteria syntax here

0
nativehuman On

The correct way to build a Criteria like that would be:

CriteriaOperator.Parse("ToInt([awayML]) > 130");