views:

554

answers:

2

I am trying to force users to only select certain values when adding a record. So naturally I am using a dropdown, but I'd like the options to be populated by a specific field in the database. I figured I'd do a Do/Loop but I am apparently doing something wrong.

Dim dstrSQL
Dim drs
    dstrSQL = "SELECT EventID FROM Events"
    set conn2 = CreateObject("ADODB.Connection")
    conn2.open CONN_STRING
    set drs = conn2.execute(dstrSQL)
    conn2.close: set conn2 = nothing
Do
        Response.Write "<option value=" & drs.Fields(0) & " >" & drs.Fields(0) & "</option>"
        drs.MoveNext
Loop
+1  A: 

Hey,

Wow, that's been a while... drs is a reader object? Don't you have to close the object after all the reading has been done, so after the loop?

Brian
+4  A: 

It's been a long time. Something like this:

conn2.open CONN_STRING
set drs = conn2.execute(dstrSQL)

do while not drs.eof %>

    <option value="<%= drs.Fields(0) %>" ><%= drs.Fields(0) %></option>
    <% drs.MoveNext
Loop
 conn2.close
 set conn2 = nothing %>
mark123
Awesome, super fast! Thanks a bunch =)
maczealot
I seem to recall needing to use the .Value property of the Field as well, so you'd have drs.Fields(0).Value inside the loop. Could be wrong though...
Mike Powell
Glad to help. :)
mark123
Maybe .Value is the default property so it's optional.
Mike Powell
if drs is a ADODB Recordset object you can also use drs("EventID")
Jon P
Jon P, I was going to say something similar. I prefer the named columns as they are easier to remember what they mean.
mark123