title: SQL Data Reader: Invalid attempt to read when no data is present
body: <p>I am trying to use a <code>SqlDataReader</code> to run a query and then display the results in a messagebox, 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 void button1_Click(object sender, EventArgs e)
   {
      string results = "";
      using (SqlConnection cs = new SqlConnection(@"Server=100-nurex-x-001.acds.net;Database=Report;User Id=reports;Password=mypassword"))
      {
           cs.Open();
           string query = "select stationipaddress from station where stationname = @name";
           using (SqlCommand cmd = new SqlCommand(query, cs))
           {
                // Add the parameter and set its value -- 
                cmd.Parameters.AddWithValue("@name", textBox1.Text);
                using (SqlDataReader dr = cmd.ExecuteReader())
                {
                     while (dr.Read())
                     {
                          label3.Text = dr.GetSqlValue(0).ToString();
                          results = dr.GetValue(0).ToString();
                          //MessageBox.Show(dr.GetValue(0).ToString());
                          //MessageBox.Show(results);
                      }
                      MessageBox.Show(results);
                }
           }
      } 
  }
  </code></pre>