How to convert type data.table to type IEnumerable


#1

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.

Regards
Suravi


How to convert DataTable to IEnumerable
#2

Hi @sushree.suravibuyan

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


#3

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)


#4

Thanks @Susana and @acaciomelo for guiding me.


#5

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.


#6

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:


#7

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