tags:

views:

522

answers:

3

In C#, is it possible to get all values of a particular column from all rows of a DataSet with a simple instruction (no LINQ, no For cicle)?

+3  A: 

As far as I know there's no direct way to get those; but the for-loop is pretty straightforward and obviously won't be more resource-intensive than anything else.

Utaal
That's what I was thinking. I was hoping it could be a way of doing it. Thanks.
Nelson Reis
A: 

In addition to Utaal's answer, you can possibly populate a new DataTable object with the results of a query that selects only one column from your original data source, assuming it's an RDBMS. This has the advantage of letting you specify things that are easy to express in code but easy to express in SQL like DISTINCT queries.

Welbog
+1  A: 

Only by iterating over the rows, as Utaal noted in this answer.

You might expect that the DataTable.DefaultView.RowFilter would support grouping, but it does not (it mainly offers the equivalent functionality of a Where clause, with some basic aggregations - though not simple grouping).

Jeff Sternal