Adding Data Tables to Queues

Referring solution provided by @ppr https://forum.uipath.com/t/adding-data-to-queue-question/738719/2,1.

Using LINQ I did group by. But all the data is in one data table. How do I get multiple data tables for each group? How do I convert each data table to a CSV string? And how do I convert the CSV back to a datatable.

Thank you,

@A_Learner

You can use .ToDictionary to create multipe tables

Dt.AsEnumerable.GroupBy(function(x) x(0).ToString).ToDictionary(function(x) x.Key,function(y) y.CopyToDatatable)

This create a dictionary (string,datatable) with key being the grouped value and value being the datatable for that group

If you use output datatable you can convert datatable to string, and using generate datatable can convert back to datatable

Hope this helps

Cheers

Hi @A_Learner ,

I would suggest converting data tables to JSON instead of CSV. I’ve faced issues with parsing CSV because there are chances that delimiters might be present within the data itself.

To convert DataTable to JSON →

Newtonsoft.Json.JsonConvert.SerializeObject(yourDtVar)

To convert JSON back to DataTable →

Newtonsoft.Json.JsonConvert.DeserializeObject(Of DataTable)(yourSerialisedJsonString)

Give it a try and let us know if it works.

Kind Regards,
Ashwin A.K

Lets assume a simple GroupBy LINQ returning a list of DataTables, representing each the grouped data

Assign Activity:

TableList | List(Of DataTable) =
(From d in dtData.AsEnumerable
Group d by k=d(0).toString.trim into grp=Group
Select t = grp.CopyToDataTable).toList

with:
Select t = grp.CopyToDataTable
the DataTable from the group is prepared for the projection

  • Output DataTable Activity OR
  • Write CSV File Activity - read resulting CSV as Text OR
  • Custom CSV conversion OR
  • Generate DataTable Activity OR
  • Read CSV File Activity OR
  • Custom CSV Parsing OR

we can exploit JSON very successfully. In case of DataTables we should keep in mind the caused string length overhead, given by the nature of JSON

can be handled within CSV when surrounding the text with a quote:
grafik

Depending on how JSON parsing is setup we also keep in mind for some scenarios

  • given - column with mixed datatype (Object, “ABC”, 123…)
  • As with the first row col value the column datatype is derrived, it can also lead to failures within the parsing as 123 is not accepted as string (it is number)

@A_Learner
just get familar with the essential building blocks, then combine all factors as you do need

2 Likes

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