SQL中一表多条件查询问题

teachnon 2008-11-27 09:12:02
页面设计为:

下拉列表+文本框

列表中数据由库中获取,代码如下:
<select size="1" name="view" style="background-attachment: scroll; background-repeat: repeat; font-size: 9pt; height: 23; width: 143; background-color: #FFFFFF; border: 1 solid #000000; background-position: none; ">
<%
SQL="Select * From jiben"
Set RS1=Server.CreateObject("ADODB.Recordset")
RS1.Open SQL,Connstr,1,1
DO While Not RS1.EOF
%>
<option value="<%=RS1("ID")%>"><%=RS1("cun")%></option>
<%
RS1.MoveNext
Loop
%>
</select>

文本框中输入年份,如:2008
求代码,按上述两个条件在表中进行数据查询并显示。
谢谢
...全文
223 25 打赏 收藏 转发到动态 举报
写回复
用AI写文章
25 条回复
切换为时间正序
请发表友善的回复…
发表回复
yaberhan 2008-11-27
  • 打赏
  • 举报
回复
学习~~
oulin1983 2008-11-27
  • 打赏
  • 举报
回复
同意16楼的想法
把text框加上名字
<form action="" method="post" name="year">
<input type="text" name="date"> </form>


SQL=sql & " where id=" & request("view") & " and year= " & cint(request("date"))"
wj121284 2008-11-27
  • 打赏
  • 举报
回复
把text框加上名字
<form action="" method="post" name="year">
<input type="text" name="date"> </form>


SQL=sql & " where id=" & request("view") & " and year= " & cint(request("date"))
anjing5566 2008-11-27
  • 打赏
  • 举报
回复
问题一,你的表中的year是数字类型吗?
问题二,既然用了form,为什么还要用cint(form.year.value),直接用cint(request("year"));

你的提交部分源码不要用图片,要直接贴html源码,没人知道你的html是怎么写的
teachnon 2008-11-27
  • 打赏
  • 举报
回复
view传送是正常的。加了后面TEXT部分就不对了。
layers2323 2008-11-27
  • 打赏
  • 举报
回复
前面一个页面有没有传递view?

把sql write出来看看。
teachnon 2008-11-27
  • 打赏
  • 举报
回复
SQL=sql & " where id=" & request("view") & " and year= " & cint(form.year.value)

提示缺少对象。
是不是method="post" 方法不对?
teachnon 2008-11-27
  • 打赏
  • 举报
回复
SQL=sql & " where id=" & request("view") & " and year= " & cint(form.year.value)

SQL="sql & " where id='" & request("view")&"' and year= '" & cint(form.year.value)&"'"

以上两条调试都不对啊!
文本框部分的代码我这样写的:
<form action="" method="post" name="year">
<input type="text" ></form>

oulin1983 2008-11-27
  • 打赏
  • 举报
回复
SQL="sql & " where id='" & request("view")&"' and year= '" & cint(form.year.value)&"'"
layers2323 2008-11-27
  • 打赏
  • 举报
回复
SQL=sql & " where id=" & request("view") & " and year= " & cint(form.year.value)
teachnon 2008-11-27
  • 打赏
  • 举报
回复
我原来只用一个条件(下拉列表中的村名)进行查询,代码如下:
<%
sql="select top 1 * from jiben"
If request("view") <>"" and Then
SQL=sql & " where id=" & request("view")
End If
set rs=server.CreateObject("adodb.recordset")
rs.Open SQL,Connstr,3,2
if rs.eof or rs.bof then
response.write "<p align='center' style='font-size:12px;color:#ff0000;'>还没有任何记录,请到添加信息窗口加入相关信息!</p>"
response.end
end if
%>

现在改为如下代码,请大家看看是否正确:
<%
sql="select top 1 * from jiben"
If request("view") <>"" and Then
SQL=sql & " where id=" & request("view") and year= " & cint(form.year.value)
End If
set rs=server.CreateObject("adodb.recordset")
rs.Open SQL,Connstr,3,2
if rs.eof or rs.bof then
response.write "<p align='center' style='font-size:12px;color:#ff0000;'>还没有任何记录,请到添加信息窗口加入相关信息!</p>"
response.end
end if
%>
oulin1983 2008-11-27
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 teachnon 的回复:]
上图有误。改下为以下图片:

[/Quote]
conn连接数据库
aa=request("option.value")
bb=request.form("年份")
select * from 表名 where 字段='"&aa&"' and 字段='"&bb&"'
set rs=con.execute(sql)
do while not rs.bof or rs.eof
response.write(.....)
rs.movenext
loop
layers2323 2008-11-27
  • 打赏
  • 举报
回复
你要sql语句?
SQL="Select * From jiben Where cun='" & form.下拉框ID.value & "' And year=" & cint(form.文本框ID.value)
teachnon 2008-11-27
  • 打赏
  • 举报
回复
本来想做成二级联动的,但看了好多帖子都搞不清楚。所以想弄简单点算了。
teachnon 2008-11-27
  • 打赏
  • 举报
回复
上图有误。改下为以下图片:

teachnon 2008-11-27
  • 打赏
  • 举报
回复

如上图,在下拉列表中选择村名,然后在文本框中输入年份,以上述两个条件进行查询
layers2323 2008-11-27
  • 打赏
  • 举报
回复
不是很明白你想做什么。
oulin1983 2008-11-27
  • 打赏
  • 举报
回复
看不懂楼主的要求什么,帮顶一下
craft001wen 2008-11-27
  • 打赏
  • 举报
回复
这不很简单的问题,想那么复杂
year是保留字,以后字段名,最好不要用这些保留字

SQL= " select * from table where 村名='"& request("view")&"' and year([year])= '" & trim(request("year"))&"'"
junying2yu 2008-11-27
  • 打赏
  • 举报
回复
Select * from yourtable where id='$s)' and year='2008)
加载更多回复(5)

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧