How to add column with its data to another data table

Can anyone help me with the approach or link query for adding the column with its data to another data table?

Thanks,
Shreyash

1 Like

@shreyash_shirbhate

you can use invoke code activity

can you share what was your input and expected output

Hello @shreyash_shirbhate

  1. Use a “Build Data Table” activity to create an empty destination DataTable (e.g., dtDestination) with the same structure as the source DataTable (e.g., dtSource).

  2. Use a “For Each Row” activity to iterate through each row in dtSource:

    • In the “For Each Row” properties, set the DataTable to dtSource.
  3. Inside the loop, use the “Add Data Row” activity:

    • In the “Properties” of the “Add Data Row” activity:
      • Set the DataTable to dtDestination.
      • In the “ArrayRow” property, add the current row from dtSource. You can use an array or an object array to pass the row.
      • Ensure that the “AddHeaders” property is set to False if your source DataTable doesn’t have headers.
  4. After the loop, dtDestination will contain the data from dtSource, and you can use it as needed.

  5. Optionally, you can use a “Write Range” activity to write the destination DataTable to an Excel file or another destination.

Thanks & Cheers!!!

@shreyash_shirbhate

if you want to fill a new column based on another column then join also can do the job

cheers

depending on the details:

  • Appending: Merge DataTable
  • Side-by-Side / Join Data: LINQ and/or essential modelling

Hi Shiva,

I have a 2 data table lets say dt1 and dt2.

I want to add the column “ABC” from dt1 to dt2 at last.

I tried using add data column using data column object but it is just copying the heading and not the data.

I followed this post by @ppr . But it is not copying my column data.

@Kartheek_Battu, I don’t want to do it with the for each loop.

I am finding out for linq/invoke code or any other easy way.

@shreyash_shirbhate

add data column is used to add a empty column

1 Like
  • Add Data Column is only creating the data column.

just be more clear in the details:

  • Data Column Value transfer - is it a side-by-side merge

please lets avoid ping-pong as sample data was asked, but not shared

1 Like

Hi @ppr,

I have a 2 data table lets say dt1 and dt2.

I want to add the column “ABC” along with the data from dt1 to dt2 at last.

unfortunately no samples was shared

Have a look if the side-by-side merge is matching your case

Hi @ppr,

Here is the sample data.

I want it something like this. It’s simple lets take Column D from dt1 and add Same Column in dt2 along with it’s data.

Hope it’s clear now.

looks like a side-by-side merge

Starter help as shared above

Help Customization: Add dt1 Last col value to dt2 as Last Col Value, where over all ColumnStructure was defined on a dtResult

Project Compatibility: Windows

(From i In Enumerable.Range(0, {dt1.Rows.Count, dt2.Rows.Count}.Max())
Let ra1 = If(i < dt1.Rows.Count, dt1.Rows(i).ItemArray, dt1.NewRow.ItemArray)
Let ra2 = If(i < dt2.Rows.Count, dt2.Rows(i).ItemArray, dt2.NewRow.ItemArray)
Let ra = ra2.Concat(ra1.TakeLast(1)).ToArray
Select r= dtResult.Rows.Add(ra)).CopyToDataTable

:grinning: My code is in window’s legacy.

(From i In Enumerable.Range(0, {dt1.Rows.Count, dt2.Rows.Count}.Max())
Let ra1 = If(i < dt1.Rows.Count, dt1.Rows(i).ItemArray, dt1.NewRow.ItemArray)
Let ra2 = If(i < dt2.Rows.Count, dt2.Rows(i).ItemArray, dt2.NewRow.ItemArray)
Let ra = ra2.Concat(ra1.Skip(ra1.Length-1).Take(1)).ToArray
Select r= dtResult.Rows.Add(ra)).CopyToDataTable

@shreyash_shirbhate
By using invoke code we can

1 Like

Hi @sasi_poosarla,

I have tried it but the data column is getting added with the empty values.

image

@shreyash_shirbhate
set arguments dt2 as in/out

I have already did it. @sasi_poosarla

@sasi_poosarla,

I think I got it wait.