title: loop returning inadequete records from database
body: <p>I have a list that is taking data from a database. It is always <strong>leaving</strong> one record that meets my database search query. when i change the database details to increase or decrease the records, it still leaves one record. out of say 8 records that meets a search criteria it returns 7, out of say 5 it returns 4 </p>
  
  <pre><code>using (SqlConnection con = new SqlConnection("Data Source=*** Initial Catalog=***y;Persist Security Info=True;User ID=***;Password=***"))//connection string
          {
              con.Open();
              SqlCommand cmd = new SqlCommand("SELECT SubjectName FROM dbo.mySubjects WHERE SubjectClass = @theSubjectClass", con);//query string 
              cmd.Parameters.Add("@theSubjectClass", SqlDbType.VarChar).Value = myClass;
              SqlDataReader dr = cmd.ExecuteReader();
              dr.Read();
              //int t = 0;
              //count = count + 1; Tried adding a counter that gets the number of raws in the table that meet the search query and create a loop based on that but it produces an error of trying to read data where there is no data to read
              while ( count &gt;= 0) {
                  dr.Read();
                  List &lt;string&gt; Subjects = new List&lt;string&gt;();
                  Subjects.Add(dr.GetString(0));
                  //t = 0;
                  foreach (var course in Subjects)
                  {
                      var a = new HtmlGenericControl("a");
                      a.Attributes["class"] = "color-info";
                      var container = new HtmlGenericControl("div");
                      container.Attributes["class"] = "col-lg-4 col-sm-6";
                      var div = new HtmlGenericControl("div");
                      div.Attributes["class"] = "card card-warning wow zoomInUp animation-delay-5";
                      var text = new HtmlGenericControl("div");
                      text.Attributes["class"] = "card-block text-center";
                      var p = new HtmlGenericControl("p");
                      text.Controls.Add(p);
                      string manage = dr.GetValue(0) + " Videos";
                      var btn = new Button
                      {
                          Text = manage,
                          CssClass = "btn btn-warning"
                      };
                      btn.Click += new EventHandler(ExploreButtonClick);
                      text.Controls.Add(btn);
                      div.Controls.Add(text);
                      container.Controls.Add(div);
                      a.Controls.Add(container);
                      Row.Controls.Add(a);
                      count = count - 1;
                  }
              }
              con.Close();
          }
  </code></pre>