Search Results:

Thursday, June 16, 2016

Filter datatable using LINQ in VB.NET

Below is a simple LINQ that you can use to filter the DataTable.


AsEnumerable() method to return the input type DataTable as IEnumerable.

CopyToDataTable() method takes the results of the filtered query and copies into a new DataTable that you can use to work with the filtered data.

-------------------------------------------------------------------------
         Dim filteredTable As DataTable = (From n In dt.AsEnumerable()
                                           Where n.Field(Of Int32)("id") = 1
                                           Select n).CopyToDataTable()
-------------------------------------------------------------------------

Feel free to leave your comments or suggestions. Thank you.