Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in RPA by (5.3k points)

I have a data table with two columns ID & Role. The same ID can have multiple roles. I need to convert this table to a comma-separated grouped table. I am trying to use the following query but unable to solve the issue.

LINQ:

From row As DataRow In dtData.Rows.Cast(Of DataRow)

Group row By id = row.Field(Of Integer)("ID") Into Group

Select ID, Role = String.Join(",", From i In Group Select i.Field(Of String)("Role"))

 

Issue enter image description here

Any help will be appreciated.

Update 1:

Table structure

enter image description here

Needed table Structure

enter image description here

1 Answer

0 votes
by (9.5k points)

try by creating a linq like in your comments just that this returns a list of arrays of string:

result of linq

Here is the code:

(From row As DataRow In myDatatable Group row By id = row.Field(Of String)("ID") Into Group Select {id, String.Join(",", From i In Group Select i.Field(Of String)("Role"))}).ToList

If you need the result in a datatable you can build a new datatable

create newDatatable

Make a for each of result and use the activity Add data row. In ArrayRow add the item and in DataTable the new data table

Add data row properties

If you use the activity Output data table you can see the results

Output data table

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...