Harshit
Harshit

Reputation: 5157

lambda expression to get first value where

I am running this query

dr[0] = dt.AsEnumerable()
    .Where(l => l.Field<int?>("ID") == "5")
    .Select(l => new {k = l.Field<int?>("description")})
    .First()
    .ToString();

I am trying to get the description where id = 5. But it is giving error

Specified cast is not valid.

What is wrong with this query ?

Upvotes: 0

Views: 976

Answers (1)

Kelly Robins
Kelly Robins

Reputation: 7313

Check your field types - For "ID" you are comparing int to string... for "description" you are casting to an int which also doesn't look correct.

Upvotes: 4

Related Questions