printing column values for only first of two rows....

G

Guest

The datareader below contains two rows of two columns but in the for loop,
the values for only the first row are getting printed twice. How do I get to
the values of the second row? Thanks. -hazz

Dim dTable As DataTable
Dim dsBlock As New DataSet
Dim rowBlock As DataRow
Dim myColumn As DataColumn
Dim iCol As Integer = 0

dTable = dsBlock.Tables.Add("BlockInfo")
While DataReader.Read
rowBlock = dTable.NewRow()
rowBlock(0) = DataReader.Read.Item(0)
rowBlock(1) = DataReader.Read.Item(1)
dTable.Rows.Add(rowBlock)
End While

For iRow= 0 To dTableBlockInfo.Rows.Count - 1
For Each myColumn In dTable.Columns
PrintValue(iRow , iCol, rowBlock(myColumn))
iCol = iCol + 1
Next
Next
 
K

Ken Tucker [MVP]

Hi,

While DataReader.Read
rowBlock = dTable.NewRow()
rowBlock(0) = DataReader.Item(0)
rowBlock(1) = DataReader.Item(1)
dTable.Rows.Add(rowBlock)
End While


Ken
---------------------------------
The datareader below contains two rows of two columns but in the for loop,
the values for only the first row are getting printed twice. How do I get to
the values of the second row? Thanks. -hazz

Dim dTable As DataTable
Dim dsBlock As New DataSet
Dim rowBlock As DataRow
Dim myColumn As DataColumn
Dim iCol As Integer = 0

dTable = dsBlock.Tables.Add("BlockInfo")
While DataReader.Read
rowBlock = dTable.NewRow()
rowBlock(0) = DataReader.Read.Item(0)
rowBlock(1) = DataReader.Read.Item(1)
dTable.Rows.Add(rowBlock)
End While

For iRow= 0 To dTableBlockInfo.Rows.Count - 1
For Each myColumn In dTable.Columns
PrintValue(iRow , iCol, rowBlock(myColumn))
iCol = iCol + 1
Next
Next
 
G

Guest

Thank you Ken. I made a typo. It is DataReader.Item() not
DataReader.Read.Item()
Having noticed that, I still have a problem with outputting only the first
row's values twice rather than outputting the values of the first row (in my
grid) and then the column values of the second row appropriately. So what is
wrong with this? thx...

For iRow= 0 To dTable.Rows.Count - 1
For Each myColumn In dTable.Columns
PrintValue(iRow , iCol, rowBlock(myColumn))
iCol = iCol + 1
Next
Next
 
G

Guest

Well that was easy with a good night's sleep and a fresh perspective.
I wasn't looping through the rows!

For Each myRow In dTable.Rows
For Each myColumn In dTable.Columns
.SetValue(r, i, rowBlockInfo(myColumn))
i = i + 1
Next
r = r + 1
Next
 

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