Convert datatable column to list element


I want to convert the datatable columns value into list of elements.

Ps : the output should not contain duplicate values

Example : I have datatable called DT1, containing 2 columns

Name price
Apple 30
Orange 40
Apple 20

Needed this to be converted to list elements

Hi @Kavya_Bhat ,

With regards to your question, Not sure i understand as per your expectation. However, as per my understanding goes, you wanted your datatable values to be converted into list but it shouldn’t contain the duplicates. If this is correct,
try the below logic

DT_To_List = DT1.AsEnumerable().Select(Function(r) r("Name").ToString()).Distinct().ToList()

Hi @pavithra_pavi ,

It worked. Thanks

Happy to help :blush:

1 Like

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