From: BlackSun on
Hi,
I wrote this code:

Private Function Carica() As IEnumerable(Of GCA)
Return From lista In DatiBase _
Where lista.Field(Of String)(Colonna3) <> "" _
Order By lista.Field(Of String)
(Colonna2),lista.Field(Of String)(Colonna3) _
Select New GCA With {.AAAA= lista.Field(Of String)
(Colonna1), _
.BBBB= lista.Field
(Of String)(Colonna2), _
.CCCC= lista.Field
(Of String)(Colonna3) _
}
End Function
It works fine but.... how can I change to get the list with distinct
rows for Colonna3
(= GCA.CCCC)?

Thanks in advance!
Cheers,
BlackSun
From: Martin Honnen on
BlackSun wrote:

> Private Function Carica() As IEnumerable(Of GCA)
> Return From lista In DatiBase _
> Where lista.Field(Of String)(Colonna3) <> "" _
> Order By lista.Field(Of String)
> (Colonna2),lista.Field(Of String)(Colonna3) _

Group By CCCC = lista.Field(Of String)(Colonna3)
Into Group _

> Select New GCA With {.AAAA= Group.First().Field(Of String)
> (Colonna1), _
> .BBBB= Group.First().Field
> (Of String)(Colonna2), _
> .CCCC= Group.CCCC _
> }
> End Function
> It works fine but.... how can I change to get the list with distinct
> rows for Colonna3
> (= GCA.CCCC)?

See the changes I made above. But that is pseudo code to suggest how to
approach that, not tested code. You might need to post the exact
definitions of your types like DatiBase if you can't get it to work.


--

Martin Honnen --- MVP XML
http://msmvps.com/blogs/martin_honnen/
From: BlackSun on
Hi,

thank you for you help!

Cheers,
BlackSun

On 12 Gen, 18:07, Martin Honnen <mahotr...(a)yahoo.de> wrote:
> BlackSun wrote:
> > Private Function Carica() As IEnumerable(Of GCA)
> >         Return From lista In DatiBase _
> >                     Where lista.Field(Of String)(Colonna3) <> "" _
> >                     Order By lista.Field(Of String)
> > (Colonna2),lista.Field(Of String)(Colonna3) _
>
>                        Group By CCCC = lista.Field(Of String)(Colonna3)
> Into Group _
>
> >                     Select New GCA With {.AAAA= Group.First().Field(Of String)
> > (Colonna1), _
> >                                                     .BBBB= Group.First().Field
> > (Of String)(Colonna2), _
> >                                                     .CCCC= Group.CCCC  _
> >                                                     }
> >     End Function
> > It works fine but.... how can I change to get the list with distinct
> > rows for Colonna3
> >  (= GCA.CCCC)?
>
> See the changes I made above. But that is pseudo code to suggest how to
> approach that, not tested code. You might need to post the exact
> definitions of your types like DatiBase if you can't get it to work.
>
> --
>
>         Martin Honnen --- MVP XML
>        http://msmvps.com/blogs/martin_honnen/

From: BlackSun on
Hi,
> > Private Function Carica() As IEnumerable(Of GCA)
> >         Return From lista In DatiBase _
> >                     Where lista.Field(Of String)(Colonna3) <> "" _
> >                     Order By lista.Field(Of String)
> > (Colonna2),lista.Field(Of String)(Colonna3) _
>
>                        Group By CCCC = lista.Field(Of String)(Colonna3)
> Into Group _
>
> >                     Select New GCA With {.AAAA= Group.First().Field(Of String)
> > (Colonna1), _
> >                                                     .BBBB= Group.First().Field
> > (Of String)(Colonna2), _
> >                                                     .CCCC= Group.CCCC  _
> >                                                     }
> >     End Function
> > It works fine but.... how can I change to get the list with distinct
> > rows for Colonna3
> >  (= GCA.CCCC)?
>
> See the changes I made above. But that is pseudo code to suggest how to
> approach that, not tested code. You might need to post the exact
> definitions of your types like DatiBase if you can't get it to work.

Thak you for your reply... I changed the code and now it works but I
have another question....
If I would like to have distinct rows not for Column3 but for Column2
and Column3 togheter?

Ex:

Column 2 | Column3
AAA | A1A1 => OK
AAA | BBB => OK
AAA | CCCC => OK
AAA | BBB => NO
ADES | A1A1 => OK

Thak you in advance.

Cheers,
BlackSun
From: Martin Honnen on
BlackSun wrote:

>> Group By CCCC = lista.Field(Of String)(Colonna3)
>> Into Group _


> Thak you for your reply... I changed the code and now it works but I
> have another question....
> If I would like to have distinct rows not for Column3 but for Column2
> and Column3 togheter?

You can have composite grouping keys so simply use e.g.
Group By CCCC = lista.Field(Of String)(Column3), DDDD =
lista.Field(Of String)(Column2) Into Group

--

Martin Honnen --- MVP XML
http://msmvps.com/blogs/martin_honnen/
 |  Next  |  Last
Pages: 1 2
Prev: sample client server app
Next: I need help