fees_structure
has 24 "A" Category rows. But when I try to fetch them and print, it only displays 20 or (21 rows sometimes)
Here is my code:
string catA = "SELECT id,fees_name,amount,fee_category FROM fees_structure where fee_category='A' ORDER BY id";
using (SqlCommand scom = new SqlCommand(catA, con))
{
using (SqlDataReader read = scom.ExecuteReader())
{
read.Read();
if (read.HasRows)
{
while (read.Read())
{
feestableA.Append("<tr>");
feestableA.Append("<td>" + read["fees_name"] + "</td>");
feestableA.Append("<td>" + read["amount"] + "</td>");
feestableA.Append("</tr>");
}
plcfeesA.Controls.Add(new Literal { Text = feestableA.ToString() });
plcfeesA.Dispose();
}
}
}
The read()
before the while
is suspicious. I suspect that is eating one row.
Another possibility for losing rows would be case-sensitive collations -- if the category could be 'a'
(or a variant in another encoding). However, this depends on the default or explicit collations used for the column, database, and server.