Adding Headers from 1 datatable to another

I have two datatables in my workflow, dt_Certified and dt_ExtraHeaders. Both tables have no data in them, but I need to add the column headers from dt_ExtraHeaders to dt_Certified after the existing columns in dt_Certified.

dt_ExtraHeaders is currently being imported from excel. The end user requires this as they will be changing these headers as needed.

What is the simplest way to complete this task? Thanks in advance!

Hi @mbuehler

  1. Read Range (Excel) - Output to dt_ExtraHeaders
  2. Initialize List of String variables (e.g., headerList)
  3. For Each item in dt_ExtraHeaders.Columns
  • Add item.ToString to headerList
  1. For Each item in headerList
  • Add Data Column (Name: item.ToString) to dt_Certified
  1. Now, dt_Certified should have new columns with headers from dt_ExtraHeaders

Hope it helps!!

1 Like

@mbuehler

Excel Application Scope (Read dt_ExtraHeaders from Excel)
Read Range (Output: dt_ExtraHeaders, AddHeaders: True)

For Each Row (Row in dt_ExtraHeaders)
Add Data Column (DataTable: dt_Certified, ColumnName: row(“ColumnName”).ToString())

Output Data Table (Optional - Display dt_Certified to verify)

1 Like

Hi,

If both datatable have no data and unique columns, the following MergeDataTable will work. Can you try this?

Regards,

For Each columnObj in dt_ExtraHeaders.Columns (set TypeArgument to System.Data.DataColumn)

  • Add Data Column to dt_Certified, column name = columnObj.Name
1 Like

@Yoichi
Definitely the simplest way, and one that I had overlooked. Thank you!

1 Like

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