title: Use query parameters with an ODBC connection to an iSeries AS400 database in .NET?
body: <p>If I understand <a href="https://stackoverflow.com/questions/2374698/parameterized-db2-query-from-net">this link</a> correctly, I should be able to pass query parameter values to my ODBC command and have it execute successfully. It doesn't, so here's my problem code:</p>
  
  <pre><code>OdbcConnection myConnection = new OdbcConnection("DSN=myODBCConnection");
  
  myConnection.Open();
  
  OdbcCommand myCommand = myConnection.CreateCommand();
  
  myCommand.CommandText = "SELECT * FROM MyTable FETCH FIRST ? ROWS ONLY";
  myCommand.CommandType = CommandType.Text;
  myCommand.Parameters.AddWithValue("P1", 5);
  
  OdbcDataReader myDataReader;
  
  // Fails here! It doesn't recognize P1 as a parameter to pass in for ?.
  myDataReader = myCommand.ExecuteReader();
  </code></pre>
  
  <p>The code should select the first 5 rows from MyTable. Instead, it throws this error:</p>
  
  <pre><code>System.Data.Odbc.OdbcException: ERROR [42000] [IBM][System i Access ODBC Driver][DB2 for i5/OS]SQL0104 - Token ? was not valid. Valid tokens: ROW ROWS.
  </code></pre>
  
  <p>Thanks for anyone who'd like to help! And yes, if I execute a parameterless query, it works fine.</p>