Home All Groups Group Topic Archive Search About

Loop through columns of all datarows in a dataset

Author
16 Mar 2006 11:06 AM
Philip Wagenaar
I have a dataset that I queried from an excel sheet. I want to loop through
the rows, then loop through the columns and write them to a file. But I got
stuck pretty quickly:

So far:

For Each dr As DataRow In Order.Tables(0).Rows

Next

In this for each I want to start a second for each for the columns. But it
seems that a datarow does not have a columns collection I can loop through?

How can I loop through the colomns in each datarow?

Author
16 Mar 2006 11:26 AM
Armin Zingler
Show quote Hide quote
"Philip Wagenaar" <philip.wagenaar@online.nospam> schrieb
> I have a dataset that I queried from an excel sheet. I want to loop
> through the rows, then loop through the columns and write them to a
> file. But I got stuck pretty quickly:
>
> So far:
>
> For Each dr As DataRow In Order.Tables(0).Rows
>
> Next
>
> In this for each I want to start a second for each for the columns.
> But it seems that a datarow does not have a columns collection I can
> loop through?
>
> How can I loop through the colomns in each datarow?


You mean the column values?

    for each value as object in dr.itemarray


- or -

    for each col as DataColumn in Order.tables(0).columns
        dim value as object
        value = dr(col)
    next col


Armin
Author
16 Mar 2006 11:41 AM
Cor Ligthert [MVP]
Philip,

The datacolumn describe the items from the rows.

For Each dr As DataRow In Order.Tables(0).Rows
        For each it as object in dr.ItemArray
'
        next
Next

I hope this helps,

Cor

Show quoteHide quote
"Philip Wagenaar" <philip.wagenaar@online.nospam> schreef in bericht
news:95CBF6A7-1613-4023-83EF-3537ADF842DA@microsoft.com...
>I have a dataset that I queried from an excel sheet. I want to loop through
> the rows, then loop through the columns and write them to a file. But I
> got
> stuck pretty quickly:
>
> So far:
>
> For Each dr As DataRow In Order.Tables(0).Rows
>
> Next
>
> In this for each I want to start a second for each for the columns. But it
> seems that a datarow does not have a columns collection I can loop
> through?
>
> How can I loop through the colomns in each datarow?
>
>