title: MySQL ADO.Net Nested DataReaders
body: <p>I want to retrieve a list of accounts with one SQL statement, and then loop through them while running more SQL statements. When I try to, I get this error:</p>
  
  <blockquote>
    <p>Unhandled Exception: MySql.Data.MySqlClient.MySqlException: There is already an open DataReader associated with this Connection which must be closed first.</p>
  </blockquote>
  
  <p>Here's an example:</p>
  
  <pre><code>using (MySqlConnection connection = new MySqlConnection("host=..."))
  {
  
      connection.Open();
  
      using (MySqlCommand cmdAccounts = connection.CreateCommand())
      {
  
          cmdAccounts.CommandText = "SELECT id, name FROM accounts";
  
          using (MySqlDataReader accounts = cmdAccounts.ExecuteReader())
          {
  
              while (accounts.Read())
              {
  
                  Console.WriteLine("Account {0}:", account.GetString("name"));
  
                  using (MySqlCommand cmdPictures = connection.CreateCommand())
                  {
  
                      cmdPictures.CommandText = "SELECT id, width, height FROM pictures WHERE account_id = @accountId";
                      cmdPictures.Parameters.AddWithValue("@accountId", accounts.GetInt32("id"));
  
                      using (MySqlDataReader pictures = cmdPictures.ExecuteReader())
                      {
  
                          while (pictures.Read())
                          {
                              Console.WriteLine("\tPicture #{0}: {1} x {2}", pictures.GetInt32("id"), picture2.GetInt32("width"), picture2.GetInt32("height"));
                          }
  
                      }
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>Do I have to use a DataSet, or is there a way to do this in MySQL with just DataReaders?</p>