Copy Row from 1dtb to another with variable columns

Hey all

I have 1 DataTable that i need to get certain rows from and put into another DataTable and then manipulate each row of DTB2 later on.

Anywho, i first got the “This row belongs to another table” error, so i created row.ItemArray and passed it to ArrayRow property of the Add Data Row. Now im getting “Input array is longer than the number of columns in this table”

I have created ColumnCount = DTB1.Columns.Count

But how do i use that in the array? do i need to use it in array? The column number in DTB1 varies on each run and is rather large (250+)

Or is there a better way to get specific rows out of 1 dtb and into another (dont want to filter as the tasks after creating dtb2 are quiet complex and i feel dtb2 would be better than filtering dtb1)


Hello @MikeBlades
you can try below:
DataTable 1 = dt1 (old source)
DataTable 3 = dt1_new (new source)
DataTable 2 = dt2 (destination)

dt1_new = dt1.defaultview.totable(false,“Column1”,“Column3”,“Column5”) [here choose only those columns which are present in your dt2]

I can you give LINQ query for below as well if I get to know your condition

for each rw in dt1_new
next rw