Results 1 to 5 of 5

Thread: SQL query error

  1. #1
    Join Date
    Oct 2011
    Posts
    2

    Unanswered: SQL query error

    Hello,

    I am working with a page that is used for payment purposes and have an SQL query that looks like this:

    rs.Open"SELECT * FROM Java_Forms WHERE AppletTransID = ", + CStr(TransID) ,DOLData,1,3

    the TransID variable is an int. Every time that I try to run this I get a type mismatch error. If I try to change the + character before the CStr function to an &, I get a syntax error message.

    Does anyone have an idea?

    Thanks!

  2. #2
    Join Date
    Nov 2004
    Posts
    1,427
    Provided Answers: 4
    I am not fluernt in Access. I think the problem is the comma. Remove it.
    And I think you will have to use "&" instaed of "+".

    Code:
    rs.Open"SELECT * FROM Java_Forms WHERE AppletTransID = ", + CStr(TransID) ,DOLData,1,3
    Try this:
    Code:
    rs.Open"SELECT * FROM Java_Forms WHERE AppletTransID = " & CStr(TransID), DOLData, 1, 3
    With kind regards . . . . . SQL Server 2000/2005/2012
    Wim

    Grabel's Law: 2 is not equal to 3 -- not even for very large values of 2.
    Pat Phelan's Law: 2 very definitely CAN equal 3 -- in at least two programming languages

  3. #3
    Join Date
    Oct 2011
    Posts
    2

    SQL query error

    Thanks Wim,

    But if I try that I get an "Incorrect syntax near '='" error

    The db server I am working with is an SQL server.

    Thanks again

  4. #4
    Join Date
    Nov 2004
    Posts
    1,427
    Provided Answers: 4
    What is the host programming language? VB?
    How do you concatenate stings in that language? with "&", "+", ...?
    What is the string delimiter in that language? " or '?

    How would you concatenate the two strings "Hi, " and "funkyspirit"?
    a) SET MyString = "Hi, " & "funkyspirit"
    b) MyString = 'Hi, ' + 'funkyspirit'
    c) .....?

    Apply those rules to your code.

    Or try.
    Code:
    SET SQLString = "SELECT * FROM Java_Forms WHERE AppletTransID = " & CStr(TransID)
    rs.Open SQLString, DOLData, 1, 3
    If that fails, print SQLString in a message-box or so, so you can verify what SQL code you created.
    With kind regards . . . . . SQL Server 2000/2005/2012
    Wim

    Grabel's Law: 2 is not equal to 3 -- not even for very large values of 2.
    Pat Phelan's Law: 2 very definitely CAN equal 3 -- in at least two programming languages

  5. #5
    Join Date
    Sep 2011
    Posts
    71
    Hello funkyspirit,
    I think that your problem is in using function CStr(TransID), So What's the type of Column
    AppletTransID string or int ,If int so please remove CStr function

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •