while datareader.read - only returning last item

Discussion in 'ASP General' started by BenM, Jan 31, 2005.

  1. BenM

    BenM Guest

    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!
    BenM, Jan 31, 2005
    #1
    1. Advertising

  2. BenM

    Patrice Guest

    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" <> a écrit dans le message de
    news:...
    > 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!
    Patrice, Feb 1, 2005
    #2
    1. Advertising

  3. BenM

    Morris Guest

    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.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
    Morris, Feb 1, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Lozzi

    Arraylist only display last item

    David Lozzi, Feb 13, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    728
    David Lozzi
    Feb 13, 2006
  2. keithb
    Replies:
    2
    Views:
    7,991
    keithb
    Jun 7, 2006
  3. Read only last line-

    , Feb 18, 2006, in forum: C Programming
    Replies:
    35
    Views:
    932
    S.Tobias
    Mar 3, 2006
  4. sangram
    Replies:
    16
    Views:
    1,966
  5. Johny
    Replies:
    8
    Views:
    385
Loading...

Share This Page