Click here to Skip to main content
13,049,814 members (72,496 online)
Rate this:
Please Sign up or sign in to vote.
See more:
protected void Page_Load(object sender, EventArgs e)
                con = new SqlConnection();
        con.ConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True";
        ds = new DataSet();
        string sql = "SELECT * FROM Internet";
        da = new SqlDataAdapter(sql, con);
        da.Fill(ds, "Internet");
        Maxrows = ds.Tables["Internet"].Rows.Count;
        Label2.Text = inc.ToString();
        Label3.Text = Maxrows.ToString(); // displays the number of rows
    private void Records()
        drow = ds.Tables["Internet"].Rows[inc];
        Label1.Text = drow.ItemArray.GetValue(1).ToString();

protected void Button1_Click(object sender, EventArgs e)
if (inc <= Maxrows )
            Label2.Text = inc.ToString(); // outputs the row number which is being displayed
I have this above code and I am trying to display a number of records from a database on a web application. when I first load the page it load the first record. I click the next button and displays the second button. I have 3 records but the 3rd record never displays why? please can anyone help?
Posted 28-Mar-13 22:13pm
Hariharan Arunachalam 29-Mar-13 5:16am
I can't see any problem as to why the last record wouldn't show based on the data you have provided. Are you sure its not a null/empty value?

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

As you said there are 3 records then inc should vary from 0 to 2.
& Condition if (inc <= Maxrows ) should be if (inc < Maxrows ).
Please debug you code & check what r the values.
joanne danastasi 29-Mar-13 4:45am
not its in vain it still displays the first two records.
joanne danastasi 29-Mar-13 4:46am
the button only execute the code once since the label never increments to 3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 29 Mar 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100