Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

asp: trouble comparing 2 values

Options
  • 28-11-2007 5:38pm
    #1
    Registered Users Posts: 872 ✭✭✭


    Hi,

    im trying to compare 2 values but it doesnt seem to be matching (using jscript) :
    var course =  rs("coursename");
                    
                    Response.Write("course: "+course);
                
                    rs.moveNext(); // [I]move to next record to compare with first one[/I]
                    
                    while(!rs.eof && course != rs("coursename"))
                    {
                        Response.Write("<Br>current: "+rs("coursename"));
                        rs.moveNext();
                    }
    

    The condition in the while loop should run about 10 times but it isnt running at all !

    Any help would be great.


Comments

  • Registered Users Posts: 7,468 ✭✭✭Evil Phil


    Have you checked the contents of the recordset?


  • Registered Users Posts: 872 ✭✭✭grahamor


    yeah it's deffo a string.

    I changed
    rs("coursename"); to new String(rs("coursename"));
    

    and now it seems to work.


  • Registered Users Posts: 11,980 ✭✭✭✭Giblet


    Do a print on rs("coursename");

    new String() takes a few arguments.


  • Moderators, Society & Culture Moderators Posts: 9,689 Mod ✭✭✭✭stevenmu


    JScript works a little different to VBScript, got caught out with this myself recently. The line
    var course =  rs("coursename");
    
    creates a reference called course pointing to rs("coursename"), therefore when rs("coursename") changes, course effectivly does aswell. The VBScript equivelent would just copy the value from rs("coursename") into a new variable course, and would behave as you are expecting it to. What you want to use is
    var course =  rs("coursename").Item;
    
    (or maybe it's .Value)


Advertisement