Data type mismatch in criteria expression.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • veda55536
    New Member
    • Aug 2008
    • 1

    Data type mismatch in criteria expression.

    Hi,

    I've been trying to execute below query in C#.(DataBase :Access)

    strTemp = "SELECT Students.Studen tid, Persons.FirstNa me FROM (Persons INNER JOIN Students ON Persons.PersonI d = Students.Person Id) " +
    "WHERE Students.Studen tid not in ( select UnableToEnterSc hools.Studentid from UnableToEnterSc hools where UnableToEnterSc hools.SchoolId = " + SchoolId.ToStri ng() + ")";

    i.e...

    SELECT Students.Studen tid, Persons.FirstNa me FROM (Persons INNER JOIN Students ON Persons.PersonI d = Students.Person Id) WHERE Students.Studen tid not in ( select UnableToEnterSc hools.Studentid from UnableToEnterSc hools where UnableToEnterSc hools.SchoolId = 1)

    I'm getting below ERROR message,

    Data type mismatch in criteria expression.

    Please help me out in passing this obstacle.

    Thanks in advance.

    Regards,
    Bob
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by veda55536
    .. where UnableToEnterSc hools.SchoolId = " + SchoolId.ToStri ng() + ")";

    ..
    Your problem is probably in the quote above.
    If the datatype of UnableToEnterSc hools.SchoolId is some numeric value then you shouldn't be calling ToString() on SchoolId.ToStri ng(). That would mean you are comparing a numeric column with a character column.

    Comment

    • Curtis Rutland
      Recognized Expert Specialist
      • Apr 2008
      • 3264

      #3
      I don't think that's the problem, r0. Since that is just the string building part, that's ok.

      I think that you should post the actual string. Like, do a MessageBox or Console.WriteLi ne of the string that you build and show exactly what you are passing on to the database.

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by insertAlias
        I don't think that's the problem, r0. Since that is just the string building part, that's ok.

        I think that you should post the actual string. Like, do a MessageBox or Console.WriteLi ne of the string that you build and show exactly what you are passing on to the database.
        I see what you mean now. Perhaps the column definitions for the OP's tables should also be posted to provide more information.

        Comment

        Working...