title: database c# if (reader[""].count > 2)
body: <p>I want to create something like <code>if (reader["assignID"].count &gt; 2)</code> then something happens. But I understand that <code>MySqlDataReader</code> does not have a count function. How else should I approach this? </p>
  
  <p>I want to count the rows.</p>
  
  <p><strong>My code</strong></p>
  
  <pre><code>try
  {
      string myConnectionString3;
      myConnectionString3 = "server=localhost;uid=root;pwd=root;database=medicloud;SslMode=None;charset=utf8";
  
      MySqlConnection connection3 = new MySqlConnection(myConnectionString3);
      MySqlCommand cmd3 = new MySqlCommand();
  
      EncodingProvider ppp3;
      ppp3 = CodePagesEncodingProvider.Instance;
      Encoding.RegisterProvider(ppp3);
  
      cmd3.CommandType = CommandType.Text;
      string sqlStr2 = "Select assignID from assign where userId=@name";
      cmd3.Parameters.AddWithValue("@name", txtValue.Text);
      cmd3.CommandText = sqlStr2;
      cmd3.Connection = connection3;
  
  
      connection3.Open();
      MySqlDataReader reader1 = cmd3.ExecuteReader();
  
  
      if (reader1.HasRows)
      {
          while (reader1.Read())
          {
              if (reader1["assignID"].count &gt; 2) //count rows if more than 2
              {
                  txtAssignID1.Text += "Hello";
              }
              else
              {
                  btnStart.IsEnabled = true;
                  string assignID = (reader1["assignID"].ToString());
                  txtAssignID1.Text += "Your exercise ID is: " + assignID;
              }
          }                                                                                             
      }
      else
      {
  
          txtAssignID1.Text += "You have not been assigned any exercise ID";
          txtAssignID.IsEnabled = false;
      }
  
      connection3.Close();
  }
  catch (MySqlException)
  {
  
  }
  </code></pre>