title: InvalidOperationException: Invalid attempt to read when no data is present. (SQL)
body: <pre><code>      SqlConnection conn = new SqlConnection(AllQuestionsPresented.connectionString);
  
      SqlCommand cmd = new SqlCommand(sb.ToString(), conn);
      cmd.Parameters.Add("@ThreadsID", SqlDbType.Int).Value = commentIDe;
      cmd.Parameters.Add("@CommentsID", SqlDbType.Int).Value = commentIDe;
      try
      {
          conn.Open();
          SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
  
          if (dr != null &amp;&amp; dr["Comments"] != null &amp;&amp; dr["Name"] != null &amp;&amp; dr["Date"] != null &amp;&amp; dr["UserID"]!=null)//&gt; Invalid attempt to read when no data is present.
          {
              Comment = dr["Comments"].ToString();
              UserName = dr["Name"].ToString();
              Reputation=Int32.Parse(dr["Reputation"].ToString());
              Time = (DateTime)AllQuestionsPresented.TryParse(dr["Date"].ToString());
              UserID = (Guid)dr["UserID"];
          }
          dr.Close();
      }
      finally
      {
          if (conn.State != ConnectionState.Closed)
          {
              conn.Close();
          }
      }
  </code></pre>
  
  <p>Note: I do iterate over that piece of code with while(dr.Read){}... it isnt shown here.</p>
  
  <p>Why do i get that exception and how do i get rid of it</p>
  
  <p>UPDATE:</p>
  
  <pre><code>                 while (reader.Read())//Command runs through all the ThreadIDs that i have!
                  {
                      Comments allQ = new Comments((int)reader["CommentsID"]);
                      allComments.Add(allQ);
                  }
  </code></pre>
  
  <p>Comments is the class that the code is in, and it has a method inside the constructor that runs the code that i presented.</p>
  
  <p>It could be that if the loop runs too many times.. Then the exception is being thrown am i right?</p>