[RESOLVED] Iterating through Datatable Columns
Hi,
I am wondering if it is possible to iterate using columns of datatable.
thanks
I have tried something like this:
Code:
Dim myCol As New DataColumn
Dim myRow As DataRow = Nothing
Dim myCell As New DataGridCell
For Each myCol In myDt1.Columns
For Each myCell In myCol
MsgBox(myCell.ToString)
Next
Next
Re: Iterating through Datatable Columns
A DataTable is supposed to be basically an in-memory representation of a database table. Just like for a database table, in a DataTable the data is stored in the rows, not the column. The columns just describe the data, e.g. data type, size, nullability, etc. You need to loop through the rows of the table then, for each row, loop through the columns to get the data from the field from that column in the row. When indexing a DataRow, you can use an ordinal index, i.e. number, or you can use a column name or you can use the DataColumn itself.
Re: Iterating through Datatable Columns