Using for each loop in DataTable rows collection



P Szyk
August 03, 2016 12:37 ANSWERED
I try to use for each loop to go thru DataTable rows, but despite to change variable type to System.Data.DataRow I still getting error that i can’t convert System.Data.DataTable.Rows to an IEnumerable Collection.

I try to change DataTable.Rows to list or array but still doesn’t work.

How to convert DataTable to IEnumerable

Andrzej.Kniola August 08, 2016 12:04

Can you add that workflow’s part screenshot (or pseudo code)? This seems pretty strange and I’m certain it worked before. What version you’re using?

Have you checked that DT with a foreach row activity?




Tejus Venkatesh August 10, 2016 10:24

For Each Row activity is the easier way for iterating through a data table.

However, if you’re using For Each activity (generic), then please ensure below points :

“Type Argument” must be System.Data.DataRow
"Value" field must be referring to the row in data table. .Rows (Ex: dt_InputData.Rows)
Refer to the attached screenshot - Hope this helps.




Same issue here :slight_smile: is there any solution?


So, the thing is that “item” is a complete row from that table. If you put item(0) in a write line for instance, you can get the result depending on where is the information you want to extract. It can be item(0), item(1), etc.


I’m not sure if this will help,but there might be two “For Each” activities in your studio, try Using #1


I was facing the same issue.
At first view, looping on a datarow is not possible, so I create an object to convert my datarow (i.e : ExtraitNomTLRH ) to datatable (i.e : DTNomTLRH with “ExtraitNomTLRH.Table” as value), then I use an for each row on that new object.

Hopes that could help.


same thing i did not found the solution


Did you try “my” solution?


This is probably resolved for the original poster but I am adding comments for anyone else looking for the same question:

–How to Iterate through Excel
Excel Application Scope (Activity)
Excel Read Range (Activity) into a Data table dtbSampleDataTable
TotalRows = dtbSampleDataTable.Rows.Count.ToString
TotalColumns = dtbSampleDataTable.Rows(0).ItemArray.Length
For Each Row (Activity)
Assign intCurrentColumn = 0
Assign intCurrentRow = dtbSampleDataTable.Rows.IndexOf(row)

	CellData = dtbSampleDataTable.Rows(intCurrentRow)(intCurrentColumn).ToString()

	Assign intCurrentColumn = intCurrentColumn + 1


Do you have an xaml for this?

Suppose i want to iterate through an excel file and want to get data for similar rows into a separate data table until I reach the end of file?

for example if i have members like below:
Member ID Paydate PayID
1234 23.04.2018 222
1234 27.04.2018 222
2233 23.04.2018 111
4532 24.04.2018 533
4532 25.05.2018 533

I want that Member 1234 should come in a separate data table and i should do that for all the member until end of data table. Similarly for 4532 member there should be 2 rows.




A Standard Linq Group and Select(using CopyToDataTable) will do it

dt.AsEnumerable().GroupBy(Function(x) x(“MemberID”)).Select(Of DataTable)(Function(s) s.CopyToDataTable)

image (2.4 KB)