Looping through rows in a DataView

Viewed 124142

The DataView object doesn't have a Rows property like DataTable.

How do I loop through the rows of a DataView?

4 Answers

You can iterate DefaultView as the following code by Indexer:

DataTable dt = new DataTable();
// add some rows to your table
// ...
dt.DefaultView.Sort = "OneColumnName ASC"; // For example
for (int i = 0; i < dt.Rows.Count; i++)
{
    DataRow oRow = dt.DefaultView[i].Row;
    // Do your stuff with oRow
    // ...
}
Related