Why am I getting this error with my SQL command?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Alex Dransfield
    New Member
    • Jan 2011
    • 46

    Why am I getting this error with my SQL command?

    Code:
    "SELECT STUNO, FNAME, SNAME FROM STUDENT WHERE E1='4721/01  ' OR E2='4721/01  ' OR E3='4721/01  ' OR E4='4721/01  ' OR E5='4721/01  ' OR E6='4721/01  ' OR E7='4721/01  ' OR E8='4721/01  ' OR E9='4721/01  ' OR E10='4721/01  ' OR E11='4721/01  ' OR E12='4721/01  ' OR E13='4721/01  ' OR E14='4721/01  ' OR E15='4721/01  ' OR E16='4721/01  ' OR E17='4721/01  ' OR E18='4721/01  ' OR E19='4721/01  ' OR E20='4721/01  ' OR E21='4721/01  ' OR E22='4721/01  ' OR E23='4721/01  ' OR E24='4721/01  ' OR E25='4721/01  ';"
    I get the error that no value was given for one or more required parameters. This command works fine in Access SQL view, but I get an error when I use it in C#. I think there's an escape character somewhere but I can't figure out what it is. Can anyone help me?
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    I believe Access SQL uses double quotes as a string delimiter as opposed to single quotes.

    Comment

    • Plater
      Recognized Expert Expert
      • Apr 2007
      • 7872

      #3
      Does the table STUDENT actually contain columns called "E1" up through "E25"?
      [code=SQL]

      SELECT STUNO, FNAME, SNAME
      FROM STUDENT
      WHERE
      E1='4721/01 '
      OR E2='4721/01 '
      OR E3='4721/01 '
      OR E4='4721/01 '
      OR E5='4721/01 '
      OR E6='4721/01 '
      OR E7='4721/01 '
      OR E8='4721/01 '
      OR E9='4721/01 '
      OR E10='4721/01 '
      OR E11='4721/01 '
      OR E12='4721/01 '
      OR E13='4721/01 '
      OR E14='4721/01 '
      OR E15='4721/01 '
      OR E16='4721/01 '
      OR E17='4721/01 '
      OR E18='4721/01 '
      OR E19='4721/01 '
      OR E20='4721/01 '
      OR E21='4721/01 '
      OR E22='4721/01 '
      OR E23='4721/01 '
      OR E24='4721/01 '
      OR E25='4721/01 ';

      [/code]

      Comment

      • Sfreak
        New Member
        • Mar 2010
        • 64

        #4
        Does c# knows that you are passing these quotes to the string?

        for example:
        Code:
        string Ex = "\'hi\'";

        Comment

        Working...