CriTT CriTT - 2 months ago 8
Vb.net Question

vb linq comma seperatet

i have a little problem with linq in datatable vb. i try to get mixed result from double grouping but don't know how.

the result should be like this

Auftrags-Nr. | TrackingNo
1 - 39414718
2 - 95712583 ,42579525


The datatable looks like this:

Auftrags-Nr. | | TrackingNo
1. 1 - 39414718
2. 1 - 39414718
3. 1 - 39414718
4. 1 - 39414718
5. 1 - 39414718
6. 2 - 95712583
7. 2 - 95712583
8. 2 - 95712583
9. 2 - 42579525
10. 2 - 42579525


My Code looks like this

Dim trackdict = From rsx In datatbl Select rsx
Group By bla = rsx.Field(Of String)("Auftrags-Nr.") Into blagroup = Group
Select New With {Key bla, .trackingNo = ", " & bla("TrackingNo")}


Anybody know a solution?

greetings

Answer

something like this

Dim trackdict As Dictionary(Of String, String) = datatbl.AsEnumerable.
    GroupBy(Function(r) r("Auftrags-Nr.").ToString, Function(r) r("TrackingNo")).
    ToDictionary(Function(g) g.Key, Function(g) Join(g.Distinct.ToArray, ", "))