Run sql query in DataTable

I have a DataTable in C # that I am returning from a SQL server. I am passing this dataset to combine individual functions.

Is it possible to send some query directly to the DataTable, instead of iterating over all the records?

eg

set|subset|value
1  |1     |40
1  |2     |30
1  |3     |35
2  |1     |10
2  |2     |15
2  |3     |20

how can i do something like SELECT DISTINCT SET FROM TABLEand get the values 1and2

+5
source share
1 answer

Just use LINQ, it's easier.

var result = yourTable.AsEnumerable().Select(f => f.Field<int>("Set")).Distinct();
+6
source

All Articles