Add 2 array to Datatable


I have 2 arrays:

arr1 = {apple, banana, orange}
arr2 = {1,2,3}

I need to save the values to a datatable.

DT = {fruit, amount}

I usually use this syntax to convert an array to DT, any way if I can do this in 2 array and save them to a DT with 2 columns?

arr1.Select(Function (x) DT.Rows.Add(New Object(){x})).CopyToDataTable


Create one build dataTable columnNames-> fruit, amount->Output Dt_out

Take one for each row mention Arr1

Take one more for each row Arr2

Now take one add data row

in array of row mention like this


DataTable Dt_Out



Hope the following helps you.

dt = arr1.Select(Function (x,i) dt.Rows.Add(New Object(){x,arr2(i)})).CopyToDataTable


dt = arr1.Zip(arr2,Function (x,y) dt.Rows.Add(New Object(){x,y})).CopyToDataTable


1 Like

Thank you! This is what I am looking for

1 Like

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