1 Replies - 3458 Views - Last Post: 28 March 2013 - 10:20 AM Rate Topic: -----

#1 beginnerda  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 28-March 13

displaying the next record in C#

Posted 28 March 2013 - 08:44 AM

I have the below code I am trying to display records one after each other on clicking the next button. but for some reason it only displays the firs two. What should I do

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 - 1)
{

Records();

Label2.Text = inc.ToString();
}

}

Is This A Good Question/Topic? 0
  • +

Replies To: displaying the next record in C#

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5676
  • View blog
  • Posts: 12,194
  • Joined: 02-June 10

Re: displaying the next record in C#

Posted 28 March 2013 - 10:20 AM

Please fix your code tags. Its not rocket science and its explained all over including the box where you pasted your code.

Posted Image

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 - 1)
   {
      Records();
      Label2.Text = inc.ToString();
   }
} 


This is pretty meaningless to us.
No idea what the Records() method does.
No idea what the labels are for because of bad names (Label2 tells us nothing)
No idea was drow is.

But looks like basic debugging would tell you something.
If it only works for 2 records then it stands to reason the if condition in line 11 is failing. You have an equals there. Do you mean less than?

if (inc < Maxrows)
{
   // blah
   // blah
   // blah
}



tlhIn`toq's FAQ list

Learning to debug one's own code is an essential skill. Sadly, one that apparently few college courses teach. Silly if you ask me.

Placing breakpoints and walking through the code line by line allows you to actually WATCH it execute.

Visualizing what your code does will let you see why it behaves the way it does.

It would be well worth your time to do the tutorials on FAQ 2. A couple hours learning this skill will save you hundreds of hours of confusion in one project alone.


TOP most asked:
What does this error message mean?
FAQ 2: How do I debug
FAQ 3: How do I make Class1/Form1 talk to Class2/Form2


FAQ (Frequently Asked Questions - Updated Feb 2013
Spoiler



This post has been edited by tlhIn`toq: 28 March 2013 - 10:20 AM

Was This Post Helpful? 2
  • +
  • -

Page 1 of 1