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.

1 Like

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

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 Likes

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

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.

same thing i did not found the solution

Did you try “my” solution?
Regards

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
1 Like

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

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

2 Likes

I have a similar question. Tried above things but could not get a solution. Infact, I am confused with the above solutions

Steps:

  1. All the Records will be segregated as types(type 1, type2 etc) in the excel sheet. Column exists to specify which type the record belong to
  2. Using “Filter datatable” to get only specific type records.
  3. Used “For each row” to loop through the records in the Data table.

My question is how to loop through the column values for a given row inside “for each row” activity.

I am looking to avoid activities like ‘Get row item’, ‘Read cell’ etc.

It will be really helpful if one can provide .xaml file

BlankProcess2.zip (10.2 KB)
Hi Ramesh,

Not sure if you are ooking for something like this.

Thanks
Archana

Hi mzaki,

Could you please provide any .xaml file for this…I couldn’t get the process after for each row activity

Thanks

Hi Archana,

Thanks for your reply.

The solution I am looking for should consists of two things.

  1. “For each row” activity where I iterate through rows.
  2. “For each” activity in the body of “for each row activity” to iterate through columns.

number of columns are constant and no:of rows are dynamic

Hi Alice,

I have red a unstructured text file by regex. I used regex to find values for each column like name, last name, date, etc. Each of them saved as ienumerable variables. Now I want them to iterate through the text file and save in a data table and extract them in a excel file. But I do not know how to do that, specially with ienumarable data.
Can you please suggest a way?