Loop through columns of all datarows in a dataset

G

Guest

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?
 
A

Armin Zingler

Philip Wagenaar said:
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
 
C

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top