Using for each loop in DataTable rows collection

datatable
excel
loop
activities

#1

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
#2

Andrzej.Kniola August 08, 2016 12:04
Hi,

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?

Regards,

Andrzej


#3

Tejus Venkatesh August 10, 2016 10:24
Hi,

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.

Regards

Tejus


#4

Same issue here :slight_smile: is there any solution?


#5

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.


#6

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


#7

Hi,
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.
Alice.


#8

same thing i did not found the solution


#9

Did you try “my” solution?
Regards


#10

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
End

#11

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.

Thanks,
Har


#12

Hi,

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

ColsToDts.zip (2.4 KB)

Cheers