title: Dapper query with DateTime
body: <p>I'm trying to use <code>Dapper</code> to query a table from my <code>ODBC</code> driver. The specific query I'm trying to run needs to return rows that have a <code>DateTime</code> value greater than the passed parameter to the query.</p>
  
  <p>This is what I have tried:</p>
  
  <pre class="lang-cs prettyprint-override"><code>string delta = "05/02/2019 08:41:37";
  DateTime deltaDt = DateTime.Parse(delta);
  
  using (IDbConnection connection = new OdbcConnection(/**Connection string**/))
  {
      connection.Open();
  
      try
      {
          string query = "SELECT * FROM MyTable WHERE Date &gt; @Delta";
          IEnumerable&lt;object&gt; records = connection.Query&lt;object&gt;(query, new { Delta = deltaDt });
  
          Console.WriteLine(records.Count());
      }
      catch (Exception ex)
      {
          Console.WriteLine(ex.Message);
      }
  }
  </code></pre>
  
  <p>However, with the above I get the following error:</p>
  
  <pre><code>{"ERROR [22018] Cannot convert non-numeric data"}
  </code></pre>
  
  <p>I then tried using <code>IDBConnection</code> without <code>Dapper</code> to see if I was just doing something incorrect, however the query works fine if I just do the following:</p>
  
  <pre class="lang-cs prettyprint-override"><code>string delta = "05/02/2019 08:41:37";
  DateTime deltaDt = DateTime.Parse(delta);
  
  using (IDbConnection connection = new OdbcConnection(/**Connection string**/))
  {
      connection.Open();
  
      string odbcQuery = "SELECT * FROM MyTable WHERE Date &gt; ?";
  
      IDbCommand command = connection.CreateCommand();
  
      IDbDataParameter parameter = command.CreateParameter();
      parameter.Value = deltaDt;
      command.Parameters.Add(parameter);
  
      command.CommandText = odbcQuery;
      System.Data.IDataReader reader = command.ExecuteReader();
      while (reader.Read())
      {
          object[] values = new object[1];
          reader.GetValues(values);
          console.log(values);
      }
  }
  </code></pre>
  
  <p>Am I doing something wrong when binding the <code>DateTime</code> using the <code>Dapper</code> query? As far as I can see the value is the same whether I use <code>Dapper</code> query or <code>IDbDataParameter</code>. I have also tried the following, but still get the same issue:</p>
  
  <pre class="lang-cs prettyprint-override"><code>string query = "SELECT * FROM MyTable WHERE Date &gt; @Delta";
  DynamicParameters dp = new DynamicParameters();
  dp.Add("@Delta", deltaDt, DbType.DateTime);
  IEnumerable&lt;object&gt; records = connection.Query&lt;object&gt;(query, dp);
  </code></pre>