Need help to combine two different list variables values into a single data table with two columns

Hi Everyone,

Hope you are doing good

I have two list variables with data

List1 - {1,2,3}
List2 - {Pen, Pencil, Paper}

I need an output in a data table like below

ID Name
1 Pen
2 Pencil
3 Paper

Can anyone help me with the logic?

Hi,

If length of List1 and List2 are same, the following will work.

dt = listA.Zip(listB,Function(a,b) dt.LoadDataRow({a,b},False)).CopyToDataTable

Sample
Sample20240722-1.zip (3.1 KB)

Regards,

@divya.x.kuchi

 Build Data Table
    - Columns: ID (Int32), Name (String)
    - Output: DataTable outputDT
Assign
    outputDT = (From id In List1.Zip(List2, Function(i, n) New Object() {i, n}).ToList
                  Let row = outputDT.NewRow
                  Select outputDT.Rows.Add(row.ItemArray = id)).CopyToDataTable()

Hie @divya.x.kuchi
use two build datatable which hold ID and Name column
image
Assign your data in Array of string and array of int use two for each to pass the data one by one
image
and your your data in add data row
use two write data table one hold the first value and secound hold the next value
hope it help. and in the property section check the add header option.
image
mark this if it helpful for you cheers and happy Automtion

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