Search code examples
devexpresscriteriaxpo

Create correct Criteria Operator


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?


Solution

  • 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