Search This Blog

Monday, February 16, 2015

Select DataTable rows with where LINQ C#

C# > LINQ > Where

Where filters a sequence of values based on a predicate. 

Example

Select DataTable rows with where.


DataTable dt = new DataTable();
dt.Columns.Add("name", typeof(string));
dt.Rows.Add("john");
dt.Rows.Add("dan");

var filteredRows = dt.Rows
                  .Cast<DataRow>()
                  .Where(r => r["name"] == "dan").ToList();