Comparaison Problems in ASP DB form

Results 1 to 2 of 2

Thread: Comparaison Problems in ASP DB form

  1. #1
    Join Date
    Dec 1969

    Default Comparaison Problems in ASP DB form

    I&#039;ve created an ASP page using JScript which allows users to edit existing records in an Access Database over the net.<BR><BR>One of the things i want my page to do is to initially load all form objects on the page with the values of those controls currently stored in the database. (ex. If the "FirstName" field in my database record reads "John Smith", I want this value loaded automatically into the "FName" textfield on my form.)<BR><BR>This is working perfectly except in the case of drop-down menus. I use a script to populate all my drop-down menus, and want to use a comparaison between: <BR> 1. The value of the control stored in the database.<BR> 2. All possible values of the control.<BR>to determine which of the possible values for the control should be initially selected.<BR><BR>However, my comparaison doesn&#039;t seem to work!<BR>I&#039;m trying to do this:<BR> if (rsTable("ModID") == rsPriority("ModID"))<BR>where the rsTable object is the contents of the database record, and ModID is a field of type "Number", and the rsPriority object contains one of the possible values of the form control. This comparaison is iterated over all possible values of rsPriority.<BR><BR>But, i found that even when the values ARE equal, this comparaison returns false!<BR>I even tried using formatString() on BOTH objects before the comparaison, and that didn&#039;t work either.<BR><BR>Any ideas?<BR><BR>Thanks!<BR><BR>- Colin<BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default Objects in the mirror...

    ...are really objects, *not* values.<BR><BR>You seem to be under the mistaken impression that rsTable("ModID") is giving you a numerical value. Nope, it is giving you an instance of an ADODB.FIELD object! Or, rather, a reference to one.<BR><BR>Then rsPriority("ModID") *also* give a ref to an instance of an ADODB.FIELD object.<BR><BR>And so your code<BR>if (rsTable("ModID") == rsPriority("ModID"))<BR>is *really* saying "if those two object references are identical", which is equivalent to saying "if the addresses of the two objects are the same".<BR><BR>See? No comparison of the values, implicit or explicit.<BR><BR>The easy fix:<BR><BR>if (rsTable("ModID").value == rsPriority("ModID").value)<BR><BR>Extract the value property of each object and you&#039;re off and running.<BR><BR>Why does rsTable("ModID") return an object reference instead of a value? Because there are *many* possible properties and methods that you might have intended to use, instead of the value. For example, maybe you really intended to test:<BR><BR>if (rsTable("ModID").type == rsPriority("ModID").type)<BR><BR><BR><BR>

Posting Permissions

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