How to copy a whole dt column into another dt

Hello all,

I have a question that I couldn’t answer by checking other threads. I have to read an Inpuf file (with around 2000 rows and 35 columns) and then I have to paste the value of the Input file columns into Report File, but the order of the columns are different.

Ex: Column A InputFile = Column D ReportFile

How can I copy the value of a whole column from my DT1 (Input File) to a DT2 (Report File) in a specific order, so I can paste the whole DT2 into the Report excel directly?

PD: Using FOR EACH ROW is not efficient for what we need to do. Also, we have already thought of a read range for each column in the Input file to paste it in the Report file as we need to, but we are looking for a DT solution.

Thank you all!

you can use link query to do that

Hi @l.sestafes,

You can do that as follows.
Suppose you have 4 columns A,B,C,D in datatable DT1, and you want to write in order A,C,D,B in DT2. then

use assign DT2 = DT1.DefaultView.ToTable(false,“A”,“C”,“D”,“B”)

Then write DT2.

1 Like

Hello @Sree_Krishnan_vellinezhi,

Could you please explain it a bit more? I’m afraid I dont understand what you mean.

will the order of the columns change dynamically in second DT

Hello @shankm,

You are the best!! Thank you so much for your help!

1 Like

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