1

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?

Ole Pannier
  • 3,208
  • 9
  • 22
  • 33
Trey Balut
  • 1,355
  • 3
  • 19
  • 39

2 Answers2

2

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

Nikita K
  • 406
  • 2
  • 8
  • Nikita, I checked the DevExpress reference and changed my code to the following: " XPCollection collection = new XPCollection(session1, CriteriaOperator.Parse("ToInt[awayML]) >130")); " and I'm still getting an error "Message=Parser error at line 0, character 13: syntax error; ("ToInt[awayML]{FAILED HERE}) >130")" – Trey Balut Aug 09 '21 at 13:52
  • ToInt[(Value]) not available in version 10.1 of DevExpress Library – Trey Balut Aug 10 '21 at 12:44
2

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

CriteriaOperator.Parse("ToInt([awayML]) > 130");
nativehuman
  • 117
  • 1
  • 11