我有要求,从组合框/下拉列表中选择多个(超过一个/两个/三个)选项/值,这些值我需要通过sql查询,你能不能请我最早帮助我。
<table border="0" cellpadding="0" cellspacing="0">
<tr class="f10pt">
<td width=90px><b>Country:</td>
<td><select multiple name="Locale" class="f8pt" style="width:80px;">
<option value="">All Locales</option>
<%
SQLstr="Select country_id,country_text from dbo.country with (NOLOCK) order by country_id Asc"
DocDBRecords.open SQLstr, DOCDB, adOpenStatic, adLockReadOnly
if not DocDBRecords.bof And not DocDBRecords.eof Then
Do While Not DocDBRecords.Eof
Response.Write "<option value=""" & DocDBRecords("country_id") & """"
If Len(CountryQuery)>0 Then
If (CInt(DocDBRecords("country_id"))=CInt(CountryQuery)) Then
Response.Write " SELECTED"
End If
End If
Response.Write ">" & DocDBRecords("country_text") & "</option>"
DocDBRecords.movenext
Loop
End If
DocDBRecords.close
%>
</select>
答案 0 :(得分:0)
您有选择多个表单元素。如果您选择多个选项,则选项将以逗号分隔的字符串形式发送。
然后你可以做这样的事情
selectname = Request.Form("yourselectname")
selectarray = split(selectname,",")
For Each item In selectarray
sql ="Insert into yourtable (yourfield) values('" & item & "')"
conn.Execute sql
Next
如果要将值传递给选择查询,一个选项是使用VBS替换功能将逗号更改为“或countryid =”,例如
idstring = replace(Request.Form("countryid"),","," or where countryid = ")
sql="Select country_id,country_text from dbo.country where countryid = "& idstring
如果您的表单位于面向公众的网站上,我强烈建议您使用某种正则表达式函数,表单数据在发送到数据库之前必须通过该函数,否则您会对SQL注入攻击持开放态度