title: SQL DataReader: Invalid attempt to read when no data is present to label
body: <p>I am trying to use a SqlDataReader to run queries on two tables where the 1st column in the Selection table is a foreign key referencing to the Items table, and then display the results in labels, but I keep getting the error:</p>
  
  <blockquote>
    <p><em>Invalid attempt to read when no data is present.</em></p>
  </blockquote>
  
  <p>Here is my code:</p>
  
  <pre><code>public partial class Read : System.Web.UI.Page
      {
          SqlConnection conn = new SqlConnection(@"data source = localhost; integrated security = true; database = dev_handin1");
          SqlCommand cmd = null;
          SqlDataReader rdr = null;
          string sqlsel = "SELECT MainItemId FROM Selection";
  
          protected void Page_Load(object sender, EventArgs e)
          {
              if (!IsPostBack)
              {
                  GetInfo();
              }
          }
  
          private void GetInfo() {
              try
              {
                  cmd = new SqlCommand(sqlsel, conn);
                  conn.Open();
                  sqlsel = "SELECT * FROM Items WHERE ItemId = MyMainItem";
                  rdr = cmd.ExecuteReader();
  
                  var MyMainItem = rdr[0];
  
                      while (rdr.Read())
                      {
                          LabelCategory1.Text = rdr[1].ToString();
                          LabelHeadline1.Text = rdr[2].ToString();
                          LabelText1.Text = rdr[3].ToString();
                          LabelJoke1.Text = rdr[4].ToString();
                      }
              }
              catch (Exception ex)
              {
                  LabelMessage1.Text = ex.Message;
              }
              finally
              {
                  rdr.Close();
                  conn.Close();
              }
          }
      }
  }
  </code></pre>
  
  <p>I'm pretty new at this so please bear with me.</p>