Compare number from DB to a form string in ASP

Discussion in 'HTML' started by Noozer, Sep 15, 2004.

  1. Noozer

    Noozer Guest

    I'm having a brainfart here...

    Writing an ASP page and the following is never evaluating as true:
    if request("Branch") = rsSet("BranchKey") then response.Write " selected
    "

    Branch is a SELECT value passed from a previous form submission.
    BranchKey is a number stored in an MS Access database.

    I'm assuming that the problem is that Branch returns a string (even though
    it holds a number) and that rsSet("BranchKey") is returning a number and not
    a string.

    I've verified that both are returning similar values (ie Branch is "12" and
    BranchKey is 12).

    How can I make this comparison work? (or what group should I ask in - didn't
    see anything ASP related)

    Thanks!
     
    Noozer, Sep 15, 2004
    #1
    1. Advertising

  2. Noozer

    Augustus Guest

    "Noozer" <> wrote in message
    news:pg22d.20023$%S.17360@pd7tw2no...
    > I'm having a brainfart here...
    >
    > Writing an ASP page and the following is never evaluating as true:
    > if request("Branch") = rsSet("BranchKey") then response.Write "

    selected
    > "
    >
    > Branch is a SELECT value passed from a previous form submission.
    > BranchKey is a number stored in an MS Access database.
    >
    > I'm assuming that the problem is that Branch returns a string (even though
    > it holds a number) and that rsSet("BranchKey") is returning a number and

    not
    > a string.


    you are correct... all form items, even if its a number, come in as a string

    First you want to check if request("branch") is numeric (just to be safe,
    else you'll get a 500 asp error)

    Then, if it is numeric you want to convert it to a number...

    Something like:

    IF ISNUMERIC(request("branch")) THEN
    if CINT(request("Branch")) = rsSet("BranchKey") then response.Write "
    selected"
    END IF

    ISNUMERIC() is a boolean function... it will return "true" if the item in
    brackets is numeric... and "false" if it is not.
    CINT() is a function that will convert a string or other number to an
    integer. If it cannot convert the string it will return an error (I say "or
    other number" because 12345 is an integer... 12345.678 is NOT an integer
    because it has a decimal point with value other than 0 after it...
    CINT(12345.678) would return 12345)
     
    Augustus, Sep 15, 2004
    #2
    1. Advertising

  3. Noozer

    Noozer Guest

    > > Writing an ASP page and the following is never evaluating as true:
    > > if request("Branch") = rsSet("BranchKey") then response.Write "

    > selected
    > > "
    > >
    > > Branch is a SELECT value passed from a previous form submission.
    > > BranchKey is a number stored in an MS Access database.
    > >
    > > I'm assuming that the problem is that Branch returns a string (even

    though
    > > it holds a number) and that rsSet("BranchKey") is returning a number and

    > not
    > > a string.

    >
    > you are correct... all form items, even if its a number, come in as a

    string
    >
    > First you want to check if request("branch") is numeric (just to be safe,
    > else you'll get a 500 asp error)
    >
    > Then, if it is numeric you want to convert it to a number...
    >
    > Something like:
    >
    > IF ISNUMERIC(request("branch")) THEN
    > if CINT(request("Branch")) = rsSet("BranchKey") then response.Write "
    > selected"
    > END IF
    >
    > ISNUMERIC() is a boolean function... it will return "true" if the item in
    > brackets is numeric... and "false" if it is not.
    > CINT() is a function that will convert a string or other number to an
    > integer. If it cannot convert the string it will return an error (I say

    "or
    > other number" because 12345 is an integer... 12345.678 is NOT an integer
    > because it has a decimal point with value other than 0 after it...
    > CINT(12345.678) would return 12345)


    Thanks! That's just what I needed... I was trying to use VAL() .
     
    Noozer, Sep 19, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. FC
    Replies:
    3
    Views:
    408
    Ioannis Vranos
    Mar 4, 2005
  2. w00
    Replies:
    5
    Views:
    1,063
  3. Replies:
    10
    Views:
    793
  4. Replies:
    10
    Views:
    777
    Roland Pibinger
    Jan 24, 2007
  5. Replies:
    2
    Views:
    450
Loading...

Share This Page