变量中的缺失值

2022-01-16 00:00:00 sql asp-classic html sql-server vbscript

我正在尝试在具有经典 ASP/VBScript 的站点上使用 <option> 填充 <select>.这些值是从 SQL Server 数据库读取和获取的,其代码类似于:

I'm trying to populate a <select> with <option>'s on a site with Classic ASP/VBScript. The values are read and taken from an SQL Server Database and the code for that looks similar to:

SET rows = dbc.execute(SQL)
    IF NOT rows.EOF THEN
        DO WHILE NOT rows.EOF
             %>  
                <option value="<%=rows("specialty")%>"><%=rows("specialty")%></option>
             <%    
             rows.moveNext
        LOOP
    ELSE    
END IF

rows.close
SET rows = NOTHING

我遇到的问题是 <%=rows("specialty")%> 似乎只有一侧在评估.

The problem I have is that only one side of the <%=rows("specialty")%> seems to evaluate.

<option value="<%=rows("specialty")%>"><%=rows("specialty")%></option> 我明白了:

<option value="fromRow1"></option>
<option value="fromRow2"></option>
<option value="fromRow3"></option>

使用 <option value="test"><%=rows("specialty")%></option> 我得到:

<option value="test">fromRow1</option>
<option value="test">fromRow2</option>
<option value="test">fromRow3</option>

应该怎么做才能缓解这个问题?

What should one do to mitigate this issue?

推荐答案

试试这个:

Dim a
Do while not rows.Eof
    a = rows.Collect("specialty")
    Response.Write("<option value=""" & Replace(a, """", "&quot;") & """>" & a & "</option>")
    rows.MoveNext
Loop

相关文章