Convert a DataTable column into an Array

Hello, my problem is this:

I have a DataTable, and I need to get all the unique values from one column of this DataTable, in one Array.

In other words, I need a VB.net expression in which the input is the DataTable and its column and returns an array with the unique values.

The expression I tried was:

[DT_name].DefaultView.ToTable(true, “ColumnName”)

But the output was a list type.

Thanks for the help!

lets assume we want to get a string array
DT_name.AsEnumerable.Select(Function (x) x(YourColNameOrIndex).toString).toArray

for unique values we add distinct()
DT_name.AsEnumerable.Select(Function (x) x(YourColNameOrIndex).toString).Distinct().toArray

2 Likes

Thanks Man! That’s exactly what I needed. It worked!

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