[英]How to fill a Select with data from SQL Server? Using ASP Classic
I'm a newbie programming on ASP Classic and I'm trying to fill a Select with information from SQL Server tables, but I got trouble trying to separate two columns, I need put a column on Value side and the other one outside option just for display the name of the option. 我是ASP Classic上的新手编程,我试图用SQL Server表中的信息填充Select,但是尝试分隔两列时遇到了麻烦,我需要在Value侧放置一列,而在外部放置一个选项用于显示选项的名称。
I'm trying to get this: 我试图得到这个:
<option value="Field_1">Field_2</option>
I'm trying with different loop ways, but I still am getting 2 columns combined inside my value. 我正在尝试使用不同的循环方式,但是我的值中仍然合并了2列。
Like this: 像这样:
<option value="Field_1Field_2"> </option>
This is my code - I appreciate any ideas. 这是我的代码-感谢您提出任何建议。
Thanks 谢谢
set rs = Server.CreateObject("ADODB.Recordset")
SQL = "SELECT id_geren, Acron FROM tbl_geren"
rs.open SQL, conect
<html>
<body>
<select id="" style="width:65px">
<% do until rs.EOF %>
<option value=
<% for each x in rs.fields %>
<% Response.Write(x) %>
<% next
rs.MoveNext %>
></option>
<% loop
rs.close
%>
</select>
</body>
</html>
I expect the output like this: 我期望这样的输出:
<option value="id_geren">Acron</option>
but the actual output is: 但实际输出是:
<option value="id_gerenAcron"></option>
You don't need to iterate over the individual fields as they can be accessed independently; 您无需遍历各个字段,因为它们可以独立访问。
<% do until rs.EOF %>
<option value=“<%= rs(“id_geren”) %>”><%= rs(“Acron”) %>”></option>
<% rs.MoveNext %>
<% loop
rs.close
%>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.