Select column using query

How to select particular columns using column index and copy it to datatable
Input-Datatable
Output-Datatable

Linq Query suggestion?

hi @Demo_User

check this out

Hi @Demo_User

Assign Activity:
outputDataTable = inputDataTable.AsEnumerable().Select(Function(row) {
    row(1),
    row(3),
    row(4)
}).CopyToDataTable()

Explanation:

  • inputDataTable is your input DataTable variable.
  • outputDataTable is the output DataTable variable that will store the selected columns.
  • row(1), row(3), and row(4) represent the columns at index 1, 3, and 4 respectively.

Hope it helps!!

hi @Demo_User

if needed by index

New DataTable → DtOutput

(From d In Dt.AsEnumerable
let ra = d.ItemArray.Take(your index number).toArray
Select DtOutput.Rows.Add(ra)).CopyToDataTable

if needed till index 8
(From d In Dt.AsEnumerable
let ra = d.ItemArray.Take(8).toArray
Select DtOutput.Rows.Add(ra)).CopyToDataTable

Regards
nikhil

How to give this if datatable has value then i need to do this

@Demo_User
lets say you hv ur input datable variable as Dt

create a assign activity with output as DtOutput and pass the below in value

(From d In Dt.AsEnumerable
let ra = d.ItemArray.Take(your index number).toArray
Select Dt.Rows.Add(ra)).CopyToDataTable

if u need to add by column name then use this

(From d in Dt.Asenumerable
Where d(“yourcolname”).tostring.equals(“ABC”)
Select d). CopyToDatatable

@Demo_User

place a if activity condition as datatable.rows.count>0

then

use the query

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