How to convert type data.table to type IEnumerable


HI All,

I am trying to execute a mysql query and process the data in the form of datatable in a foreach loop.
It is giving me error that datatable type can’t be converted into IEnumerable type. Can anyone please help me.


How to convert DataTable to IEnumerable

Hi @sushree.suravibuyan

You could try dataTable.Select().ToList().AsEnumerable


Hello @sushree.suravibuyan,

You could also try the following example. As you can see, you may convert the datatable directly to an IEnumerable type.

Main.xaml (8.5 KB)


Thanks @Susana and @acaciomelo for guiding me.


Just a quick note, since this pops up quite a lot:

A DataTable is not an IEnumerable by itself. Internally, the .AsEnumerable() call on it actually takes the .Rows collection and converts that into an IEnumerable(Of DataRow).

That aside, since RowCollection does implement IEnumerator, you can use a ForEach loop on yourDataTable.Rows or use a ForEachRow activity on yourDataTable variable directly.


What about the other way around? I have an Ienumerable and I want a datarow (best i think) or data table. I Assume I need to use an assign activity but can’t work out the expression. The Read Row activity spits out an Ienumerable, and when I put it into the “Add data Row” in the “ArrayRow” input to try and build a datatable from it, the data table just gets written to csv as system.Object[]. I’ve put a couple of days into this and it’s time to ask for help :frowning:


Did you ever find a solution? Cause I’m looking for the same thing :slight_smile: