Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6532361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:59:33+00:00 2026-05-25T09:59:33+00:00

The following code displays only the last record from the database. How to display

  • 0

The following code displays only the last record from the database. How to display all records?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Collections;
using System.Data.Odbc;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        string MyConString = "DRIVER={MySQL ODBC 3.51 Driver};" + "SERVER=localhost;" + "DATABASE=softmail;" + "UID=root;" + "PASSWORD=********;" + "OPTION=3";
        OdbcConnection MyConnection = new OdbcConnection(MyConString);

        MyConnection.Open();
        OdbcCommand cmd = new OdbcCommand("Select name, email, website, comments from awm_comments", MyConnection);
        OdbcDataReader dr = cmd.ExecuteReader();
        if (dr.HasRows == false)
        {
            throw new Exception();
        }
        while (dr.Read())
        {
            if (!IsPostBack)
            {
                string a = dr[0].ToString();
                string b = dr[1].ToString();
                string c = dr[2].ToString();
                string d  = dr[3].ToString();
                ArrayList values = new ArrayList();
                values.Add(new PositionData(a, b, c, d));

                Repeater1.DataSource = values;
                Repeater1.DataBind();

                Repeater2.DataSource = values;
                Repeater2.DataBind();
            }
        }
    }
    public class PositionData
    {
        private string name;
        private string ticker;
        private string val3;
        private string val4;

        public PositionData(string name, string ticker, string val3, string val4)
        {
            this.name = name;
            this.ticker = ticker;
            this.val3 = val3;
            this.val4 = val4;
        }

        public string Name
        {
            get
            {
                return name;
            }
        }

        public string Ticker
        {
            get
            {
                return ticker;
            }
        }
        public string Val3
        {
            get
            {
                return val3;
            }
        }
        public string Val4
        {
            get
            {
                return val4;
            }
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T09:59:34+00:00Added an answer on May 25, 2026 at 9:59 am

    At the moment you are creating a new ArrayList for each record; then, you’re binding that new list to the repeater and overwriting the previous binding.

    Instead, you need to add all your values to your list and only bind it once you’ve read all of your data – move your variable declaration before your loop and your DataBind invocation after your loop, like so:

        ArrayList values = new ArrayList();
        while (dr.Read())
        {
            if (!IsPostBack)
            {
                string a = dr[0].ToString();
                string b = dr[1].ToString();
                string c = dr[2].ToString();
                string d  = dr[3].ToString();
                values.Add(new PositionData(a, b, c, d));
            }
        }
    
        Repeater1.DataSource = values;
        Repeater1.DataBind();
    
        Repeater2.DataSource = values;
        Repeater2.DataBind();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using the following code to display a list of friends from my twitter profile.
The following code only displays the last .text upadate. It works as expected with
I used following code, but it displays only 2 digit of ISO country name.
Gday All, The following code displays a div based on the option that has
I am using the following code to try and display in a time in
Using the following code I have been able to display a text message when
This post concerns only IE. The last line of the following code is causing
The following code is only grabbing the value of the last result in the
hii every one, following is my code which displays 4 panel one is at
I created a grid of buttons. The following code creates the buttons and displays

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.