Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

perform sql query on DataTable

I have a DataTable in C# which I am returning from SQL server. I am passing this datatable to couple separate functions.

Can I send some sort of query directly to the DataTable, instead of looping over all records?

for example

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 TABLE and get values 1 and 2

like image 688
Andrew Avatar asked Jun 12 '12 20:06

Andrew


1 Answers

Just use LINQ, it's easier.

var result = yourTable.AsEnumerable().Select(f => f.Field<int>("Set")).Distinct();
like image 86
Bryan Crosby Avatar answered Oct 21 '22 23:10

Bryan Crosby