Rreddy
(Rreddy)
May 19, 2024, 3:28pm
1
Hi everyone, i got struck in Writing LINQ query to segregate data.
I have a datatable in that it’s having duplicate data. I need to segregate them each unique data as one list of data then i need use it another place.
I tried some LINQ query but it didn’t worked
DT.AsEnumerable().Select(Function(row) row.Field(Of Integer)(1)).Distinct().ToList()
Input data:
Output: need in for each loop
Set 1:
1
1
1
Set2 :
2
2
2
Set 3:
3
3
3
Set 4:
4
4
4
Set 5:
5
5
5
5
5
5
Anil_G
(Anil Gorthi)
May 19, 2024, 3:35pm
2
@Rreddy
Use dt.AsEnumerable.GroupBy(function(x) x("Val").ToString).ToDictionary(function(x) x.Key,function(y) y.CopyToDataTable)
This would give a dictionary of datatable …key would be each value and value would be the corresponding datatable
Cheers
Rreddy
(Rreddy)
May 19, 2024, 3:52pm
3
Hi @Anil_G how to loop this data in for each activity
I want each set as a datatable in loop.
Example:
Set 1:
1
1
1
In for each i need above values as datatable
Anil_G
(Anil Gorthi)
May 19, 2024, 3:59pm
4
@Rreddy
just use thhe above linq query in list of items in for each…
inside for each currentitem.Value will give datatable of each group for each iteration
cheers
Anil_G
(Anil Gorthi)
May 19, 2024, 4:06pm
6
@Rreddy
it is not a list…it should dictionary(string,Datatable)
cheers
Rreddy
(Rreddy)
May 19, 2024, 4:13pm
7
@Anil_G i tried same
I gave type argument as
system.collections.generic.dictionary<system.string, system.data.datatable>
But still getting this
Anil_G
(Anil Gorthi)
May 19, 2024, 4:24pm
8
@Rreddy
Its value not values …remove s
Cheers
Rreddy
(Rreddy)
May 19, 2024, 4:25pm
9
@Anil_G
I’m not getting value. That’s why using Values. I’m getting only values there. Is there any imports missing in my code for not getting this
Compiler error(s) encountered processing expression “item.Value”.
‘Value’ is not a member of 'System.Collections.Generic.Dictionary(Of String, System.Data.DataTable)
Anil_G
(Anil Gorthi)
May 19, 2024, 4:35pm
10
@Rreddy
In the list of items…add .Values
And then change type argument to datatable
And use currentitem directly as datatable
Cheers
1 Like
Rreddy
(Rreddy)
May 19, 2024, 4:46pm
11
Thanks @Anil_G it’s working
1 Like
system
(system)
Closed
May 22, 2024, 4:47pm
12
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.