locked
Reserved Word RRS feed

  • Question

  • User-305388250 posted

    Hey,

    I am using the following code to pull out information from my Access Database, but i keep receiving the following error:-

    The SELECT statement includes a reserved word or an argument name that is misspelled or missing, or the punctuation is incorrect.

    My code is shown below:-

     

    DataSet ds = new DataSet();
            string database = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=|DataDirectory|/forum.mdb;Persist Security Info=True";
            string queryStr = "SELECT threads.thread_id, COUNT(posts.thread_id) AS Replies, (threads.thread_name) AS Thread, (threads.username) AS Author, max(posts.date_posted) AS LastPosted, " +
            "FROM threads INNER JOIN posts ON threads.thread_id = posts.thread_id WHERE threads.forum_id = @forum_ID GROUP BY threads.thread_id, threads.thread_name, threads.username";
            
            OleDbConnection myConn = new OleDbConnection(database);
            OleDbCommand dbCommand = new OleDbCommand(queryStr, myConn);
            OleDbDataAdapter myDataAdapter = new OleDbDataAdapter(queryStr, myConn);
    
            dbCommand.Parameters.Add("@forum_ID", OleDbType.Integer, 10);
            dbCommand.Parameters["@forum_ID"].Value = id;
    
            myConn.Open();
            myDataAdapter.Fill(ds, "threads");
            myConn.Close();
            return ds;
        }

     Any ideas what the reserved word is?

    Thanks

    Monday, May 4, 2009 10:12 AM

Answers

  • User-442214108 posted

    join it all together without the "+" sign and try to run it in access
    then, if it still doesn't work - run it in parts -

    1st time - up to Inner join
    2nd time - up to Where clause, etc

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 4, 2009 10:26 AM

All replies

  • User-442214108 posted

    surround all field names with square brackets, and you won't need to worry about it

    Monday, May 4, 2009 10:16 AM
  • User-305388250 posted

    Hey,

    thanks for replying. Actually i realised the error was a comma. The SQL statement is now shown below:-

    string queryStr = "SELECT threads.thread_id, COUNT(posts.thread_id) AS Replies, (threads.thread_name) AS Thread, (threads.username) AS Author, max(posts.date_posted) AS LastPosted " +

    "FROM threads INNER JOIN posts ON threads.thread_id = posts.thread_id WHERE threads.forum_id = @forum_ID GROUP BY threads.thread_id, threads.thread_name, threads.username";

    But when i  run this in access i receive an error saying type mismatch in expression..?

    Any Ideas?

    Thanks

    Monday, May 4, 2009 10:20 AM
  • User-442214108 posted

    join it all together without the "+" sign and try to run it in access
    then, if it still doesn't work - run it in parts -

    1st time - up to Inner join
    2nd time - up to Where clause, etc

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 4, 2009 10:26 AM