Segregate excel data

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

@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

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

@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 is this correct

@Rreddy

it is not a list…it should dictionary(string,Datatable)

cheers

@Anil_G i tried same
I gave type argument as

system.collections.generic.dictionary<system.string, system.data.datatable>

But still getting this

@Rreddy

Its value not values …remove s

Cheers

@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)

@Rreddy

In the list of items…add .Values

And then change type argument to datatable

And use currentitem directly as datatable

Cheers

1 Like

Thanks @Anil_G it’s working

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.