A little help with getrows()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • j1c

    A little help with getrows()

    I'm using getrows to return the values from two columns in a MSSQL sql
    database. Looping through them like so:
    dim irowloop, icolloop, i
    for irowloop = 0 to ubound(instance s, 2)
    for icolloop = 0 to ubound(instance s, 1)
    response.write( "<option value=""VAL"">" ) 'get 2nd col val
    response.write( i(icolloop, irowloop))
    response.write( "</option>")
    next
    next

    How can I get the value of the second column into the VALUE=""
    attribute in the drop down?

  • Chris Hohmann

    #2
    Re: A little help with getrows()

    "j1c" <just1coder@yah oo.ca> wrote in message
    news:1100627497 .870312.274760@ z14g2000cwz.goo glegroups.com.. .[color=blue]
    > I'm using getrows to return the values from two columns in a MSSQL sql
    > database. Looping through them like so:
    > dim irowloop, icolloop, i
    > for irowloop = 0 to ubound(instance s, 2)
    > for icolloop = 0 to ubound(instance s, 1)
    > response.write( "<option value=""VAL"">" ) 'get 2nd col val
    > response.write( i(icolloop, irowloop))
    > response.write( "</option>")
    > next
    > next
    >
    > How can I get the value of the second column into the VALUE=""
    > attribute in the drop down?
    >[/color]

    Response.Write "<option value='" & Server.HTMLEnco de(instances(1, irowloop))
    & "'>"


    Comment

    • j1c

      #3
      Re: A little help with getrows()

      Sorry, but I am not sure I completely understand how that works.

      Your example gives just what I was looking for, however the content
      between the <option> tags now show both column values as items in the
      drop down.

      Comment

      • Bob Barrows [MVP]

        #4
        Re: A little help with getrows()

        j1c wrote:[color=blue]
        > Sorry, but I am not sure I completely understand how that works.
        >
        > Your example gives just what I was looking for, however the content
        > between the <option> tags now show both column values as items in the
        > drop down.[/color]

        The array created from GetRows has two dimensions. The first dimension
        corresponds to the column number, the second to the row number. To reference
        the first column in the first row, you would say
        getrowsarray(0, 0)
        (remember, the indexes are zero-based).
        To reference the second column in the first row, you would do say
        getrowsarray(1, 0)
        3rd column, second row:
        getrowsarray(2, 1)

        clear?

        I don't know why you're using a nested loop. Assuming you want the data in
        the second column to be the value, and the data in the first column to be
        the text, this should do what you want:

        for irowloop = 0 to ubound(instance s, 2)
        Response.Write "<option value='" & _
        Server.HTMLEnco de(instances(1, irowloop)) & "'>"
        response.write Server.HTMLEnco de(instances(0, irowloop))
        response.write( "</option>")
        next

        Bob Barrows
        --
        Microsoft MVP -- ASP/ASP.NET
        Please reply to the newsgroup. The email account listed in my From
        header is my spam trap, so I don't check it very often. You will get a
        quicker response by posting to the newsgroup.


        Comment

        • j1c

          #5
          Re: A little help with getrows()

          Great - thank you Bob!

          Comment

          Working...