title: How can I pass multiple named parameters using ODBC to a DB2 database
body: <p>I have to query a DB2 database using an existing ODBC connection. Executing simple queries works as expected, but as soon as I try to execute a parameterised query it doesn't work:</p>
  
  <pre><code>SELECT
      ColumnA,
      ColumnB
  FROM
      MyTable
  WHERE
      ColumnA = ? AND
      ColumnB = ?
  </code></pre>
  
  <p>Using the <code>?</code> was suggested in other posts, but I always get empty results (no error messages though). When I try the standard SQL way with named parameters (and changing the SQL statement to <code>ColumnA = @ColumnA AND ColumnB = @ColumnB</code> as shown below</p>
  
  <pre><code>odbcCommand.Parameters.AddWithValue( ColumnA", 1234 );
  odbcCommand.Parameters.AddWithValue( ColumnB", 9999);
  </code></pre>
  
  <p>the following error message is shown:</p>
  
  <p><em>System.Data.Odbc.OdbcException: ERROR [42S22] [IBM][CLI Driver][DB2] SQL0206N "@ColumnA" is not valid in the context where it is used. SQLSTATE=42703...</em></p>
  
  <p>Using <code>odbcCommand.Parameters.Add( new OdbcParameter( "ColumnA", Integer ){ Value = 1234 } );</code> instead shows that this is deprecated (and also doesn't work). I'd like to avoid using concatenated SQL statements, but I can't find a way to get parameterised queries working against a DB2 database.</p>