How to remove every columns after a specific index (C# or VB)

i want to remove every columns after a specific index in assign activity and assign to datatable directly

This is what i have tried

dt = dataTable.Columns.Cast<DataColumn>().Take(17000).CopyToDataTable();

but .CopyToDataTable(); is not working as how it does with rows , where for row i used the below line

dt = dataTable.AsEnumerable().Take(1050000).CopyToDataTable();

Hi @indiedev91

Try this

dt = dataTable.DefaultView.ToTable(False, dataTable.Columns.Cast(Of DataColumn).Take(17000).Select(Function(c) c.ColumnName).ToArray())

2 Likes

Hi @indiedev91

In case of C#:

dt = dataTable.Columns.Cast<DataColumn>().Take(17000)
    .Select(col => new DataColumn(col.ColumnName, col.DataType))
    .CopyToDataTable();

In case of vb:

Assign dt = (From col In dataTable.Columns.Cast(Of DataColumn)().Take(17000)
            Select New DataColumn(col.ColumnName, col.DataType)).CopyToDataTable()

Hope it helps!!
Regards

im trying c# one but .CopyToDataTable(); is still hoghlited in red

dt = dataTable.Columns.Cast<DataColumn>()
                    .Take(17000)
                    .Select(col => new DataColumn(col.ColumnName, col.DataType))
                    .CopyToDataTable();

Can you confirm

is it about the number of columns or rows?

For Datarows we would do:

VB.Net
dt =
dataTableVar.AsEnumerable.Take(17000).CopyToDataTable

i was having the same scenario for rows but its completed wih the help of dt = dataTable.AsEnumerable().Take(1050000).CopyToDataTable();

but i cant do the same for coulmns

we are in doubt that your datatable has 17000 columns

Please use the immediate panel and share with us the output
Understanding the 6 Debugging Panels of UiPath in the easiest way possible! - News / Tutorials - UiPath Community Forum

dataTableVar.Rows.Count
dataTableVar.Columns.Count
dataTableVar.Columns

It doesnt have , but it can , im making an activity which takes datatable as input and i want to limit the amount of data it can take

then we recommend redefining the details:

given input:

  • datatable with X columns and Data / No Data

Expected output:

  • datatable with subset of Columns and Data / No Data

Kindly note:

was already mentioned to you

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.