Convert system.collections.generic.list to System.data.dataTable in FlowChart

Hello everyone, I have created a loop in the FlowChart, an Excel should be grouped, this works so far.

Now I would like to write the grouped values into a new table, but this does not work.

What value does the write Range need to fill the new table only with the grouped values?

1 Like

Hi @NHoe

Can you share the Screenshot of the LINQ Which you are using?

In addition Share the error which you are getting?

Regards

1 Like

Hi @pravin_calvin

this is the grouping

(From d In inputDT.AsEnumerable
Group d By k=d(“Servicefall”).toString.Trim Into grp=Group
Select g=grp.CopyToDataTable).toList

and I have tried the following, which leads to the error message

1 Like

Hi @NHoe

Try the below LINQ function !

Before You have to Clone the headers from readDt and pass instead of resultdt in below expression

Dt–>InputDt
ResulDt–>Inputdt.clone

(From d In Dt.AsEnumerable
Group d By k=d(“Servicefall”).toString.Trim Into grp=Group
Let ra =New Object(){k}
Select resultDT.Rows.Add(ra)).CopyToDataTable

Regards

1 Like

Hi @NHoe ,

May I ask what do you intend to display/write range to your excel? The reason I’m asking is I don’t see any other column or aggregation/computation on your LINQ query as a result of your grouping. And as far as I know, what you’ll get will be a result similar to a “Select Distinct Servicefall” query.

If you’re intent is to display all rows but grouped, it may be achieved by just sorting a column in your Data table. Or iterate thru the result of your LINQ query as it is a List of DataTables, to get each grouping.

1 Like

I want to filter/sort by an ID and write these common rows into a new table.

1 Like

Ok. If for example, your input is something like this
image

How would your output look like? 1 table with all the rows?
image
or
1 table for each Servicefall?

1 Like

I have implemented this, but now I only get the values from the column “Service case” where I need the whole row and all ID’s are in the new table, not the grouped ones.

1 Like

i want a new table with all the same “Servicefall”

1 Like

Hi @NHoe ,

I believe you have that already. See the output of this
image
is a list of data tables grouped by Servicefall.

So what you need to do is to iterate thru that list and get the resulting datatable that is grouped by Servicefall.

Have a look at this

the output is
image

if you want them all in just 1 data table, then use Merge. However, as I pointed out, this will just look like your “original” data table sorted by “Servicefall”

1 Like

Thank you for the example, but I would like to stay in the FlowChart without the for each activity.

Flowchart:


Output:
image

Can someone tell me what the difference is between the For Each activity and a loop in a FlowChart?
Basically, I thought you could just replace them with my solution.

it was to easy, thats my Solution.

Report_grouping=(From d In inputDT.AsEnumerable
Group d By k=d(“ID”).toString.Trim Into grp=Group
Select g=grp.CopyToDataTable).toList

Write Range = Report_gruppieren.Item(ID)

What is the value of your ID?

This will work, yes, but I believe the ID in Report_gruppieren.Item(ID) is not the ID of your data table but the index of that item in the list.

If that is indeed the index, I’m not sure how you are going to access them all if you’re not going to use a loop.