title: Using dapper to attach parameters with MySql
body: <p>I got a problem using dapper to attach parameters to my MySql queries. 
  Now this may be a noobish problem, but I've beaten my head on this for the better part of 2 hours now and it's still not working.</p>
  
  <p>My problem is with the SelectWithParametersTest() function right in the middle.  Here is what I've got...</p>
  
  <p>EDIT: Ok more details.
  The actual Mysql server throws fits and says, "ERROR [07001] [MySQL][ODBC 3.51 Driver][mysqld-5.1.61-0ubuntu0.11.10.1-log]SQLBindParameter not used for all parameters".</p>
  
  <p>The actual exception gets caught at QueryInternal<code>&lt;T</code>>(...) on the line where it's executing the reader.  (using(var reader = cmd.ExecuteReader())</p>
  
  <p>When I inspect the command there are no parameters attached to it, but the param object (that was passed to the function) has my anon object in it.</p>
  
  <pre><code>using System;
  using System.Data;
  using System.Collections.Generic;
  using Dapper;
  
  class Program
  {
      static void Main(string[] args)
      {
          using (var dapperExample = new DapperExample())
          {
              //dapperExample.SelectTest();
              dapperExample.SelectWithParametersTest();
          }
      }
  }
  
  class DapperExample : IDisposable
  {
      #region Fields
      IDbConnection _databaseConnection;
      #endregion
  
      #region Constructor / Destructor
      public DapperExample()
      {
          _databaseConnection = new System.Data.Odbc.OdbcConnection("DSN=MySqlServer;");
          _databaseConnection.Open();
      }
  
      public void Dispose()
      {
          if (_databaseConnection != null)
              _databaseConnection.Dispose();
      }
      #endregion
  
      #region Public Methods (Tests)
      public void SelectTest()
      {
          // This function correctly grabs and prints data.
          string normalSQL = @"SELECT County as CountyNo, CompanyName, Address1, Address2
                               FROM testdb.business
                               WHERE CountyNo = 50 LIMIT 3";
  
          var result = _databaseConnection.Query&lt;ModelCitizen&gt;(normalSQL);
          this.PrintCitizens(result);
      }
  
      public void SelectWithParametersTest()
      {
          // This function throws OdbcException: "ERROR [07001] [MySQL][ODBC 3.51 Driver][mysqld-5.1.61-0ubuntu0.11.10.1-log]SQLBindParameter not used for all parameters"
          string parameterizedSQL = @"SELECT County as CountyNo, CompanyName, Address1, Address2
                                      FROM testdb.business
                                      WHERE CountyNo = ?B";
          var result = _databaseConnection.Query&lt;ModelCitizen&gt;(parameterizedSQL, new { B = 50 });
          this.PrintCitizens(result);
      }
      #endregion
  
      #region Private Methods
      private void PrintCitizens(IEnumerable&lt;ModelCitizen&gt; citizenCollection)
      {
          foreach (var mc in citizenCollection)
          {
              Console.WriteLine("--------");
              Console.WriteLine(mc.BankNo.ToString() + " - " + mc.CompNo.ToString());
              Console.WriteLine(mc.CompanyName);
              Console.WriteLine(mc.Address1);
              Console.WriteLine(mc.Address2);
          }
          Console.ReadKey();
      }
      #endregion
  }
  
  public class ModelCitizen
  {
      public long CountyNo { get; set; }
      public string CompanyName { get; set; }
      public string Address1 { get; set; }
      public string Address2 { get; set; }
  }
  </code></pre>