How do I use lambda expressions to filter DataRows?
问题 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! 回答1: You can use LINQ to DataSets to do this: Assert.IsTrue(dataSet.Tables[0].AsEnumerable().Where( r => ((string) r["Col1"]) == "MyValue").Count() == 1); Note, you can also do this without the call to Assert: dataSet.Tables[0].AsEnumerable().Where( r => ((string) r["Col1"]) ==