Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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 28-Mar-13 23:13pm
Comments
Hariharan Arunachalam at 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
good
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.
  Permalink  
Comments
joanne danastasi at 29-Mar-13 4:45am
   
not its in vain it still displays the first two records.
joanne danastasi at 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
0 OriginalGriff 584
1 Maciej Los 275
2 DamithSL 233
3 Sergey Alexandrovich Kryukov 209
4 BillWoodruff 200
0 OriginalGriff 6,803
1 Sergey Alexandrovich Kryukov 6,377
2 DamithSL 5,421
3 Manas Bhardwaj 4,841
4 Maciej Los 4,330


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 29 Mar 2013
Copyright © CodeProject, 1999-2014
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