It doesn't give you the value of a column because a column object has no
member that represents a single row/column value. In fact, a column has no
method or properties that are specific to a single data item in the DataTable
it belongs to.
It looks like the The default member of the column object is the ColumnName
- at least that's what I get with an expression like "dc.tostring".
The DataRow object owns an ItemArray that contains a separate item object
for each column in the table. That's why you can get to individual
row/column elements by iterating through the collection of rows - and then
indexing through the item array, like this:
Dim dt As DataTable = ds.Tables(0)
Dim dr As DataRow
Dim dc As DataColumn
For Each dr In dt.Rows
For Each dc In dt.Columns
Console.Write(dr(dc.Ordinal) & vbTab)
Next
Console.WriteLine()
Next
It looks like your indexing through columns but you're actually indexing
through the ItemArray (which is the default object for the DataRow class.)
Here's annother way. This uses the column name to reference the item array
elements, as opposed to the numeric index value. But performance will suffer:
Dim dt As DataTable = ds.Tables(0)
Dim dr As DataRow
Dim dc As DataColumn
For Each dr In dt.Rows
For Each dc In dt.Columns
Console.Write(dr(dc.ToString) & vbTab)
Next
Console.WriteLine()
Next
So, it's not a question of how "For...Next" works, it's a question of the
specific makeup of the DataRow and DataColumn classes.
HTH