How do I use lambda expressions to filter DataRows?

Viewed 61743

How can I search rows in a datatable for a row with Col1="MyValue"

I'm thinking something like

Assert.IsTrue(dataSet.Tables[0].Rows.
    FindAll(x => x.Col1 == "MyValue" ).Count == 1);

But of course that doesn't work!

5 Answers

You can try this:

var b=datatable.AsEnumerable.where(p=> p.Field<string>   
("column_name")=="desire_value").CopyToDataTable()
Related