hacky
(NotHacker)
1
hi Team,
In my project, I am having a datatable like below: dt_test
I want to count of the rows where Age = “20”
I have been trying to use below logic (seems correct): LINQ operation
But I am getting error sayign that value row is not declared.
i am using namespaces:
- System.Linq
- System.Data
- System.Data.DatesetExtension.
Experts please helps @singh_sumit @ashokkarale @jast1631
lrtetala
(Lakshman Reddy)
2
Hi @hacky
Count = DT.AsEnumerable().Where(Function(row) row("Age").ToString() = "20").Count()
Regards,
ppr
(Peter Preuss)
3
And the Where Operator
So let us know if you need C# or VB.Net Syntax
ashokkarale
(Ashok Karale)
4
@hacky,
You can use a LINQ query in UiPath to count the rows in a DataTable where the age is equal to 20. Here is how you can write it:
Assuming:
- Your
DataTable is named dt.
- The column name for age is
Age.
The LINQ query would be:
countRows = dt.AsEnumerable().Count(Function(row) row.Field(Of Integer)("Age") = 20)
Explanation:
AsEnumerable() converts the DataTable to an enumerable collection so that LINQ can be applied.
Field(Of Integer)("Age") gets the value of the “Age” column for each row.
.Count(Function(row) ...) counts the rows where the condition (age = 20) is met.
Make sure that the “Age” column is of type Integer. If it’s of another type, like String, you can modify the query accordingly:
countRows = dt.AsEnumerable().Count(Function(row) row.Field(Of String)("Age") = "20")
This query will return the count of rows where the age is 20.
LLM helped me write this but it’s validated by me.
Thanks,
Ashok 
singh_sumit
(Sumit Singh Tariyal)
5
Hie @hacky check this
your input

note : Count is a integer variable
Output
cheers Happy Automation
system
(system)
Closed
6
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.