Friday, 7 March 2014

Fill DataTable Form another DataTable with Selected Column

Private Sub CopyColumns(source As DataTable, dest As DataTable, ParamArray columns As String())
        For Each sourcerow As DataRow In source.Rows
            Dim destRow As DataRow = dest.NewRow()
            For Each colname As String In columns
                destRow(colname) = sourcerow(colname)
            Next
            dest.Rows.Add(destRow)
        Next
    End Sub

###
            Dim dt As New DataTable()
            dt ''source table
            Dim dt1 As New DataTable()
            dt1.Columns.Add("columnname", GetType([String]))
            'dt1 = dt.Clone()
            CopyColumns(dt, dt1, "columnname")

No comments:

Post a Comment