Skip to content

.Net DataTable Column Filter

January 30, 2012
Dim dtNew As DataTable = dt.DefaultView.ToTable(True, {"Column1", "Column2"})
    

OR

Dim dtNew As DataTable = FilterColumns(dt, {"Column1", "Column2"})
Public Function FilterColumns(ByRef dt As DataTable, ByRef col() As String) As DataTable
    FilterColumns = dt.Copy
    For Each dc As DataColumn In dt.Columns
        If Not col.Contains(dc.ColumnName) Then
            FilterColumns.Columns.Remove(dc.ColumnName)
        End If
    Next
End Function
    
Advertisements

From → .Net

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: