Convert IList to datatable

Hello,

I am using data service query and getting IList, I would like to convert this IList to a datatable

What is the easiest way to do this ?

thanks

Hi @adext

Please check on this

Hope this helps!!

Hello @adext Welcome to the UiPath Community Forum.

With the above intended and most suitable method, here is the quick snippet used with single assign activity.

yourDataTable = (New System.Data.DataTable()).LoadDataRow(yourIList.ToArray(), true)

Thanks

hello @shantanu_chande thank you

i get this error
image

@adext

Can you try this

image

DT=MyList.Cast(Of DataRow)().CopyToDataTable()

@adext Please find attached answer by @lrtetala which type casts the IList Element to DataRow object and then adds it to the desired datatable.

Please check and let us know.

So, we assume it is a list(Of YourEntitiyType)

Therefore the datatable will have defined the Columnstructure (we assume all DE Entity fields are needed)

As mentioned within the Links within a loop the new DataRow of the prepared DataTable will be filled with the Entity Fields

  • done with essential activities and/or LINQ

When it is about many fields we can dynamize the conversion by using:

  • JSON conversions
  • DataService Metadata info

We keep in mind:

  • a datarow belongs to a datatable (we do know the table navigation property)
  • a datarow cannot be context less created, so casts / conversions can fail on above constraint

so how for example? i’m not sure about how to create a loop doing this

hi @shantanu_chande @lrtetala , i am getting this error now

Assign: Unable to cast object of type ‘Dep.DepDT’ to type ‘System.Data.DataRow’.

thank you i tried his solution but got this error

place new Object() before the {

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