title: MS Access Error: The SELECT statement includes a reserved word or an argument name that is misspelled or missing, or the punctuation is incorrect
body: <p><strong>[Update: The query works if I hardcode in the parameters - so it has to do with the way I am adding parameters to the query]</strong></p>
  
  <p>For the life of me, I cannot figure out what the problem is here.</p>
  
  <p>Here is the query being passed to the datareader:</p>
  
  <pre><code>    SELECT * FROM (SELECT TOP ? StartDate, [ID] FROM
      (SELECT TOP ? StartDate, [ID] FROM Story 
      ORDER BY StartDate DESC, [ID] DESC) AS foo 
      ORDER BY StartDate ASC, [ID] ASC) AS bar 
      INNER JOIN Story AS t ON bar.ID = t.ID 
      ORDER BY bar.StartDate DESC, bar.[ID] DESC
  </code></pre>
  
  <p>The parameters are added in the following order:</p>
  
  <pre><code>var pNumToRetrieve = new OleDbParameter("", OleDbType.Integer) {Value = numToGet};
  var pResultSet = new OleDbParameter("", OleDbType.Integer) {Value = resultSet};
  
  _cmd.Parameters.Add(pNumToRetrieve);
  _cmd.Parameters.Add(pResultSet);
  </code></pre>
  
  <p>If I enter this query into access directly it works just fine. However, when running the query from ASP.NET, I get the following error:</p>
  
  <p><strong>The SELECT statement includes a reserved word or an argument name that is misspelled or missing, or the punctuation is incorrect.</strong></p>
  
  <p>What am I doing wrong?</p>
  
  <p>Thanks,</p>
  
  <p>Adam</p>