If I understand this link 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:
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();
The code should select the first 5 rows from MyTable. Instead, it throws this error:
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.
Thanks for anyone who'd like to help! And yes, if I execute a parameterless query, it works fine.