title: An exception of type 'System.InvalidOperationException' occurred in System.Data.dll but was not handled in user code
body: <p>I have a gridview whose value for a column </p>
  
  <pre><code>&lt;asp:HyperLinkField DataNavigateUrlFields="runId" DataTextField="PercentAnalysed" ControlStyle-CssClass="hlink" HeaderText="% ANALYSED" ItemStyle-Width="6%" DataNavigateUrlFormatString="runanalysis.aspx?runId={0}" ItemStyle-Font-Underline="true"/&gt;
  </code></pre>
  
  <p>is decided by the below code.</p>
  
  <pre><code>protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
          {
              if (e.Row.RowType == DataControlRowType.DataRow)
              {
  
                  GridViewRow item = e.Row;
                  //int myvar;
                  //Int32.TryParse(item.Cells[0].Text, out myvar);
  
                  SqlConnection con = new SqlConnection(connectionstring.ToString());
                  string selectSQL = "  SELECT COUNT(*) AS 'Count' FROM Analysed WHERE runId =@myvar group by runId";
                  SqlCommand cmd = new SqlCommand(selectSQL, con);
  
                  cmd.Parameters.AddWithValue("@myvar", item.Cells[0].Text);
                  SqlDataReader reader;
                  try
                  {   con.Open();
                      reader = cmd.ExecuteReader();
                      reader.Read();
                      if (item.Cells[8].Text.Equals("0"))
                          item.Cells[13].Text = "0";
                      else
                      {
                          if (reader["Count"].ToString().Equals("0"))
                              item.Cells[13].Text = "0";
                          else
                              item.Cells[13].Text = reader["Count"].ToString();
                              reader.Close();
                      }
                  }
  
                  finally
                  {
                      con.Close();
                  }
  
  
              }
          }
  </code></pre>
  
  <p>I tried debugging it and it gives this exception.</p>
  
  <p>The exception also says additionally that I am trying to read a value when no value is present.</p>
  
  <p>I executed the query separately and the results are fine but for some cases no data is present. So I inserted this check :</p>
  
  <p>if (reader["Count"].ToString().Equals("")) </p>
  
  <p>but still the same exception.</p>
  
  <p>Any idea ?</p>
  
  <p>Also,I just experimented with some dummy value.The column gets that value but it is very weird that it is no more a hyperlink.</p>