473,382 Members | 1,437 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

while datareader.read - only returning last item

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.CloseConne ction)
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!
Jul 22 '05 #1
2 4649
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

--

"BenM" <RE***********@ulgt.orgREMOVECAPS> a écrit dans le message de
news:A4**********************************@microsof t.com...
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.CloseConne ction)
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!

Jul 22 '05 #2
BenM wrote:
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.CloseConne ction)
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
Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Tmillwee | last post by:
I have the following while statement in my code While dataReader.read( ‘Do Stuff†End Whil The dataReader contains 19 rows of data, but the while loop continues and fails on a 20th loop. I...
20
by: Mark | last post by:
Hi all, quick question , a DataView is memory resident "view" of data in a data table therefore once populated you can close the connection to the database. Garbage collection can then be used to...
3
by: Beren | last post by:
Hello, I have an sproc to query a couple of tables, that have the same fieldnames, for example DateCreated. ------------------------------------- Select a.* , b.* From tablea a Join table b...
1
by: John Smith | last post by:
I am using .NetFramework 1.1. and SQL2K. I am calling a stored procedure and it has multiple results set and some output parameters. If the output parameter does not meet certain condition,...
3
by: tshad | last post by:
I am trying to set up a class to handle my database accesses. I can't seem to figure out how to get the return value from my dataReader from these routines (most of which I got elsewhere). They...
4
by: Shapper | last post by:
Hello, I have created a datareader function in a asp.net/vb web site. The datareader returns only one record with 2 fields: and In the same aspx.vb I want to use this values as follows:...
3
by: bdwgarth | last post by:
I am trying to open a new web page for each item returned by the DataReader. I am using JavaScript to open each new window, and using a session variable to pass the DataReader Item value to the...
2
by: David Beaven | last post by:
I am creating an aspx page to show (i.e. read only) hundreds or probably thousands of items from two database queries. The user may of course only want to read one or two pages worth. I have (I...
3
by: William | last post by:
Can someone please explain this to me. I am not understanding why this works the way it does. The commented lines are the problems Dim oleEmp as OleDbCommand Dim myFinds as OleDataReader Dim...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.