while datareader.read - only returning last item

B

BenM

I am a novice user of ASP.net, so the following might be trivial for many of
you. I am trying to iterate through a datareader object and add rows to a
table based on the recordset. Here is my code:


ws1_Members.Open()
Dim tmpSQLCmd As New OleDbCommand(tmpSQL, ws1_Members)
Dim tmpMemberReader As OleDbDataReader =
tmpSQLCmd.ExecuteReader(CommandBehavior.CloseConnection)
Dim tmpRow As New TableRow
Dim tmpRowCol As TableRowCollection
Dim tmpCell As New TableCell

While tmpMemberReader.Read
memResultsTable.Visible = True
tmpCell.Text = tmpMemberReader("name") & "<br>" &
tmpMemberReader("cust no")
tmpRow.Cells.Add(tmpCell)
memResultsTable.Rows.Add(tmpRow)
memResultsTable.DataBind()
End While

tmpMemberReader.Close()
ws1_Members.Close()


Theoretically, this should loop through the recordset, creating a new row
for each record. (There should be many rows returned). However, I am only
getting the last record displayed. I have verified my SQL, and it returns
multiple records.

Thanks in advance!
 
P

Patrice

You always works on the same cell/orw. Likely the cause of the problem. IMO
you should create a new row and cell inside your loop....


Patrice
 
M

Morris

BenM said:
I am a novice user of ASP.net, so the following might be trivial for many of
you. I am trying to iterate through a datareader object and add rows to a
table based on the recordset. Here is my code:


ws1_Members.Open()
Dim tmpSQLCmd As New OleDbCommand(tmpSQL, ws1_Members)
Dim tmpMemberReader As OleDbDataReader =
tmpSQLCmd.ExecuteReader(CommandBehavior.CloseConnection)
Dim tmpRow As New TableRow
Dim tmpRowCol As TableRowCollection
Dim tmpCell As New TableCell

While tmpMemberReader.Read
memResultsTable.Visible = True
tmpCell.Text = tmpMemberReader("name") & "<br>" &
tmpMemberReader("cust no")
tmpRow.Cells.Add(tmpCell)
memResultsTable.Rows.Add(tmpRow)
memResultsTable.DataBind()
End While

tmpMemberReader.Close()
ws1_Members.Close()


Theoretically, this should loop through the recordset, creating a new row
for each record. (There should be many rows returned). However, I am only
getting the last record displayed. I have verified my SQL, and it returns
multiple records.

Thanks in advance!

You would be best advised asking this question in a dotnet news group.
This one deals with classic asp. Try
microsoft.public.dotnet.framework.aspnet

Paxton
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top