I’m using this part of code in my system.
double countA = 0.00;
double countB = 0.00;
if (myrow.grade == "A")
{
countA += 1.00;
}
else if (myrow.grade == "B")
{
countB += 1.00;
}
countALabel.Text = Convert.ToString(countA);
countBLabel.Text = Convert.ToString(countB);
The code is supposed to calculate how many student in my examMarks table that get “A” or “B” and display it using labels. However I keep getting 0 value even if there are students who get “A” and “B” in my table?
How do i get the increment value?
I refactored your code a bit. I hope you won’t mind.
I added a ‘test’ variable that will tell you if the problem is within the code or outside the code. Also, try putting a breakpoint and watch the value of ‘myrow.grade’. Goodluck!