Get distinct values from column and write into a list

HI All,

Can anyone help me on how to get distinct values from a column in a datatable to a list or array.
Thank you

1 Like

Hi @divyaag,

Kindly check this.

Regards,
Sasikumar K

@Sasi.lalo : it is throwing an error. can you please help

Hi @divyaag

Check this

Datatable dt = Datatable.DefaultView.Totable(true, list of column names)
Thanks
Ashwin.S

1 Like

Using .net, you could do this:

dt1.AsEnumerable.Select(Function(r) r("columnname").ToString.Trim ).Distinct.ToArray

You can also manipulate it inside the Select if desired. Or, use .Where() before the select to only take rows that meet certain conditions.

Regards.

9 Likes

Hi ,
It can help you.

Regards
Balamurugan.S