How could I copy the info of a datatable and paste it in another with LINQ?

My question is very simple.
I started with LINQ days ago because the RPA activities sometimes are slow when in an Excel are more than 50.000 values, so I don’t have too much experience.
The question about my problem is:

For example, I have 2 excels => Excel1 and Excel2 (this 2 excels have the same headers but differet info)
I want to obtain all the info of Excel1 with LINQ without the headers, and then paste this info in the Excel2 at the same columns but under the info that Excel 2 have.

It’s simple, but I can’t becuase I can’t find a resource of info. So, I you can help me with the question and show me a link where how to learn LINQ I will appreciate it. Thank you!!

welcome to the forum

Your case sounds more like a case of using merge datatable. had you tried so far?

For starting LINQ also have a look here:

Thank you about the forum, seems fantastic to learn.

About the question, I didnt’ try with merge datatable, is the easiest way to pay the info of a excel under the info of the other excel? Is only do that.

When only the Excel IS needed Then WE would use append range Activity and will add dt1 Data to the Worksheet having dt2 data

Could you give me pls and example about how will you do it?

we assume there is a worksheet in excel containing dt2 data
we do have additional data in a datatable dt1

then the modelling would look like this:

Okey, works fine, but It takes so long because it’s more than 50.000 values, so how would you do it with LINQ? Thanks a lot.

Datatable - we can handle with LINQ
EXCEL - we are using the provided activities

we do understand from this that your case is related to Excel, rigth?

Yes, but for example, with the first solution that you give me (append range) when the info of the other excel is pasted, remove the info and it’s paste it on the info, not under. Why?

lets shift to a common namings
Excel - Worksheets - Rows and Columns
Datatable - Rows and columns

we would interpretate that

In a Excel on a Worksheet datatable data are added to the already existing data on the end,
This we do with append range.

In case of the result is different / not within your expectations then please share with us some sample data and a screenshot of your implementation/XAML. Thanks

Yeah, the result it’s different, because the info it’s not pasted under.
I find this way to do it with LINQ but doesn’t work:

(From d In tablaMB51SAP.asenumerable
Let ra = d.itemarray
Select tablaMB51Almacenes.rows.add(ra)).copytodatatable

do it like this:
Assign activity
LHS: CountAddedRows | DataType: Int32

(From d In tablaMB51SAP.asenumerable
Let ra = d.itemarray
Select tablaMB51Almacenes.rows.add(ra)).Count

I don’t undertand what is LHS and RHS


1 Like

Okey, I have good news. Finally works so fine and fast with append range. So thank you very much, but I have a question. If I want to obtain all the info minus the last row, what could I do?
Thanks for all seriously :heart:

lets assume we do have a datatable and want to get all rows except the last one.

Assign activity
LHS: dtNew | DataType: DataTable
RHS: YourDataTableVar.AsEnumerable.Take(YourDataTableVar.Rows.Count - 1).CopyToDataTable

But lets keep the scope of this topic to only 1 case. This helps others easier to find a solution for their cases

so it is working. Please close the topic by:
Forum FAQ - How to mark a post as a solution - News / Tutorials - UiPath Community Forum

Okey, and this solution that you give me works fine to :ok_hand:

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