DataTable table = new DataTable(); // ... add columns and data to table ... DataView dv = new DataView(table); dv.Sort = "Column1 ASC"; foreach (DataRowView row in dv) { Console.WriteLine(row["Column1"]); }
DataTable table = new DataTable(); // ... add columns and data to table ... DataView dv = new DataView(table); dv.RowFilter = "Column2 = 'some value'"; foreach (DataRowView row in dv) { Console.WriteLine(row["Column1"]); }This creates a DataView from the DataTable, and then sets the RowFilter property to only include rows where "Column2" equals "some value". The foreach loop then iterates over the filtered rows, outputting the value of "Column1" for each row. Both of these examples use the System.Data library, which is included in the .NET framework.