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.
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.
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.
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.
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
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.
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?