DataTable.Select()
I am building a simple photo gallery application with ASP.NET as a hobby and as part of that excercise I wanted to find out what is the max and min value of certain column in a DataTable that I have stored in memory.
So, I thought I would use the Select() method. I wrote:
DataRow[] last = dt.Select("Max(Taken)");
which resulted in an error message: Filter expression 'Max(Taken)' does not evaluate to a Boolean term.
Hmm, what is going on here? Based on my SQL background that would have been a legal select expression. But DataTable.Select() is not a SQL processor, so next I turn to help. No real explanation there (at least I didn't find one). After a some goo... err, searching I found this. Turns out that Select() always returns me a set of original DataRows, so the original query can be written like this:
DataRow[] last = dt.Select("Taken = Max(Taken)");
I can't wait for the day when I can do these things with LINQ ...