开发者

Populate Dropdown from SQL in Classic ASP

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


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 %>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜