Click here to Skip to main content
15,886,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
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";
        con.Open();

        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
       Records();
        con.Close();
    }

    private void Records()
    {
        drow = ds.Tables["Internet"].Rows[inc];
        Label1.Text = drow.ItemArray.GetValue(1).ToString();
        inc++;

    }


protected void Button1_Click(object sender, EventArgs e)
    {
if (inc <= Maxrows )
        {

            Records();
            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
Comments
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

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.
 
Share this answer
 
Comments
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900