locked
Invalid SQL Statement RRS feed

  • Question

  • User931778073 posted

    Hi all I get the error Invalid SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT', or 'UPDATE, when I run my app.  The following is my query to check if a particular username password pair exists in Access database. 

    SELECT Count(*)
    FROM JobSeeker
    WHERE [Password] = [@Password]  AND [User Name]= [@uName];
    

    Can someone please explain why I am getting this error message, thanks in advance.

    Tuesday, August 28, 2012 6:57 PM

Answers

  • User931778073 posted

    This problem has been resolved thank you everyone. It turned out there was something wrong with my C# code.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 29, 2012 9:53 PM

All replies

  • User-1407477457 posted

    I'm not sure because I don't work with Access, but the square brackets around your parameters look like they don't belong.

    Tuesday, August 28, 2012 7:41 PM
  • User-1360095595 posted
    I think wih Access you need to use ? Instead of named parameters.
    Tuesday, August 28, 2012 8:33 PM
  • User931778073 posted

    Hello all, I have tried [?], [@?], without success. Please help.

    Tuesday, August 28, 2012 9:39 PM
  • User-1199946673 posted

    Can you try:

    SELECT Count(*) 
    FROM JobSeeker 
    WHERE [Password] = @Password AND [User Name]= @uName
    

    Or

    SELECT Count(*) 
    FROM JobSeeker 
    WHERE [Password] = ? AND [User Name]= ?
    

     

    If this doesn't work, please show your complete code?

     

    Wednesday, August 29, 2012 2:05 AM
  • User-1199946673 posted

    I think wih Access you need to use ? Instead of named parameters.

    No, Both will work...

     

    Wednesday, August 29, 2012 2:05 AM
  • User3866881 posted

    WHERE [Password] = [@Password]  AND [User Name]= [@uName]; 
    

    Hi,

    "[]" this token is to include a key word in Access, but to define an OleDbCommand's parameter, you don't need to do this. You can just add the prefix of "@" or "?"

    Thanks!

    Wednesday, August 29, 2012 9:42 PM
  • User931778073 posted

    This problem has been resolved thank you everyone. It turned out there was something wrong with my C# code.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 29, 2012 9:53 PM