A little help with getrows()

J

j1c

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(instances, 2)
for icolloop = 0 to ubound(instances, 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?
 
C

Chris Hohmann

j1c said:
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(instances, 2)
for icolloop = 0 to ubound(instances, 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?

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

j1c

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.
 
B

Bob Barrows [MVP]

j1c said:
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.

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(instances, 2)
Response.Write "<option value='" & _
Server.HTMLEncode(instances(1,irowloop)) & "'>"
response.write Server.HTMLEncode(instances(0, irowloop))
response.write("</option>")
next

Bob Barrows
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top