#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2011
    Posts
    2
    Rep Power
    0

    Database fields to reference Arrays in ASP


    As a relative beginner to ASP, please do not scream NEWBIE too loudly when reading/answering...

    I have an ASP page that displays items for a user to choose by clicking a radio button to select. Rather than manually build each item's display I have stored all the attributes of the item in an Access database and build the display dynamically.

    Since I need to reference the items later I load the attributes into arrays like this:

    itemrow = 0
    Do While Not recordset.EOF
    itemradio(itemrow) = Recordset("radname")
    itemdesc(itemrow) = Recordset("Item")
    itemcost(itemrow) = Recordset("itemcost")
    itemvalue(itemrow) = Recordset("itemvalue")
    itemimage(itemrow) = Recordset("Image")
    itemrow = itemrow + 1
    Recordset.MoveNext
    Loop
    Recordset.Close
    Connection.Close

    In the database radname would contain values like:
    0
    1
    2
    3
    4
    etc

    When the form is submitted, I grab the value and store it in a field.

    function get_radio_value()
    {
    for (var i=0; i < document.form1.group1.length; i++)
    {
    if (document.form1.group1[i].checked)
    {
    var rad_val = document.form1.group1[i].value;
    document.form1.chose.value = rad_val;
    return true;
    }
    }
    }

    Here is where I have issues. I am sure it is something I am doing or perhaps the type of field in the database that is causing it, but when I attempt to reference the information using the code below I constantly get a Type Mismatch no matter what type of field I set it to in the Access database.

    varchose = Request.form("chose")
    response.write(itemradio(varchose))


    Is there some type of conversion I need to do? I have tried setting the database field to text length 2, long, integer etc.

    ANY help would be so greatly appreciated!!

    Thanks in advance!
  2. #2
  3. No Profile Picture
    Grumpier old Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2003
    Posts
    14,424
    Rep Power
    4539
    Show a snippet of the actual code and identify what line in the code is causing your error. Often it's an unexpected null value in a variable you expected to have data.

    You can also look at the recordset .getrows() method to automatically build an array from a recordset.
    ======
    Doug G
    ======
    The man who doesn't read good books has no advantage over the man who can't read them.
    --Mark Twain
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2011
    Posts
    2
    Rep Power
    0
    response.write(itemradio(varchose))

    is the line where it is giving me the Type Mismatch, I put it in there as a way to debug and verify that the correct array item was being chosen.

IMN logo majestic logo threadwatch logo seochat tools logo