I have a two column table containing CustomerName and Age columns. I have all the data in a DataTable. I want to sort it by descending Age and then each age group is sorted by name. So all people aged 30 will be sorted alpabetically and be between lists of people aged 29 and 31 etc.
I have:
string selectStatement = "Age";
string sortStatement = "Age DESC"
var rows = table.Select(selectStatement, sortStatement);
This should sort by age. I haven’t figured out how to sort each age group alphabetically but the above throws an exception:
Filter expression ‘Age’ does not evaluate to a Boolean term.
Like @adrift said. You should send a filter expression (which evaluates to boolean) as a first argument. Try to send null and an empty string there, maybe Select will ignore the argument. Or give it some trivial expression like 0<1. And then in the order by part, you can just seperate several fields by commas: “Age Desc, Name”.
But even better, you should use DataView class. Like this:
Then you can set this class as a datasource for some controls, etc. It will return rows in correct order.
Or you can simply use foreach to iterate over rows.