Welcome to MSDN Blogs Sign in | Join | Help

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 ...

Published Monday, January 29, 2007 7:14 PM by AaliAlikoski
Filed under: ,

Comments

# re: DataTable.Select()

Or you could use DataTable.Compute()!

Monday, January 29, 2007 9:16 PM by Matt Hamilton

# re: DataTable.Select()

Great comment, I didn't remember Compute() was there also!

Tuesday, January 30, 2007 2:17 AM by AaliAlikoski
New Comments to this post are disabled
 
Page view tracker