How to query a DataTable using LINQ in C# and VB.NET

To query a DataTable using LINQ in C# and VB.NET you can use the snippet below.
In order to use the snippet, you need to reference System.Data.DataSetExtensions.

Sample C#

var resultData = (from myDataRow in myDataTable.AsEnumerable() where myDataRow.Field<Int32>("Fieldname") == 1 select myRow);

Sample VB.NET

Dim resultData = (From myDataRow In myDataTable.AsEnumerable() Where myDataRow.Field(Of Int32)("Fieldname") = 1myRow)

3 thoughts on “How to query a DataTable using LINQ in C# and VB.NET

Leave a Reply