title: DataReader returns no rows -- rows are present in database
body: <p>Okay world, I'm having some trouble. No, this is not 'homework'</p>
  
  <p>I've got some code which needs to do two things:<br>
  1) Read a list of artists from a database<br>
  2) Find all tracks written by that artist and store it for later</p>
  
  <p>What I'm doing:<br>
  1) <code>SELECT ArtistID FROM artists</code> gets me my list of artists. I build it up in a <code>List&lt;string&gt;</code> datatype, using a <code>DataReader</code>, etc. works great<br>
  2) <code>SELECT count(*) as track_numbers from tracks WHERE ArtistID = @ArtistID</code> does not work so great</p>
  
  <p><strong>My problem</strong>:<br>
  The second select statement will succeed if I manually specify the <code>ArtistID</code> (ie: <code>SELECT count(*) as track_numbers FROM Tracks WHERE ArtistID = 0</code> works) but if I am iterating through my list, it will always return zero results.</p>
  
  <p>I am using <em>Connector/Net 6.3.6</em>, <em>Visual Studio 2010</em> (all updates), <em>.NET 4.0 Client Profile</em>, <em>MySQL Community Server 5.5.9 x64</em>, <em>Windows 7 Home Premium x64</em></p>
  
  <p>I have tried:</p>
  
  <ul>
  <li>Using string concatenation to build up my query string with the artistid </li>
  <li>casting artistid as a string, then an int, then vice-versa </li>
  <li>re-arranging where the parameters are defined, the value put in, the command text</li>
  </ul>
  
  <p>Relevant (I think) code below:</p>
  
  <pre><code>List&lt;string&gt; list = new List&lt;string&gt;();
  Hashtable table = new Hashtable();
  DbProviderFactory factory = DbProviderFactories.GetFactory(setting.ProviderName);
  using (DbConnection conn = factory.CreateConnection())
  {
  conn.ConnectionString = setting.ConnectionString;
  conn.Open();
  
  using (DbCommand cmd = conn.CreateCommand())
  {
      cmd.CommandType = CommandType.Text;
      cmd.CommandText = "SELECT ArtistID FROM artists;";
      using (DbDataReader reader = cmd.ExecuteReader())
      {
          while (reader.Read())
          {
              list.Add(reader["ArtistID"].ToString()); //this works, and I can iterate no problem through this list
          }
      }
  }
  
  using (DbCommand cmd = conn.CreateCommand())
  {
      cmd.CommandType = CommandType.Text;
      cmd.CommandText = "SELECT count(*) as counts FROM tracks WHERE ArtistID = @ArtistID;";
      //cmd.CommandText = "SELECT count(*) as counts FROM tracks WHERE ArtistID = 0;"; &lt;-- this line works
  
  
      DbParameter param = cmd.CreateParameter();
      param.ParameterName = "@ArtistID";
  
      foreach (string artist in list)
      {
          param.Value = artist;
          cmd.Parameters.Add(param);
          using (DbDataReader reader = cmd.ExecuteReader())
          {
              while (reader.Read())
              {
                  Console.WriteLine(artist + "\t" + reader["counts"]); //reader["counts"] is always '0'
              }
              cmd.Parameters.Clear();
          }
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>The database table format is: 
  Artist has one value/key called <code>ArtistID</code>, type <code>int</code><br>
  Tracks has three columns, <code>TrackID (int, pk)</code>, <code>artistid (int)</code>, <code>albumid(int)</code></p>
  
  <p>Any suggestions? Thanks.</p>