注册 登录
编程论坛 ASP技术论坛

[求助]关于下拉列表传值的问题

sldtk1 发布于 2007-10-10 18:49, 1863 次点击

各位好,我刚学ASP,很多地方不懂,来请教一下

<form id="form1" name="form1" method="post" action="2.asp">
产品编号:
<select name="id" size="1">
<option value="1" selected>1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
<input type="submit" name="Submit" value="提交">
</form>

以上是表单页面
下面是处理页面

<html>
<body>
<% ID=request.form("id") /%>
<%
dim con,DBPath
set con=server.CreateObject("ADODB.Connection")
DBPath=server.MapPath("data.mdb")
con.open "driver={Microsoft Access Driver(*.mdb)};dbq="&DBPath
set rs=server.CreateObject("ADODB.Recordset")
sql="select * from data"
sql=sql & "where 产品编号 like '%"& ID &"%'"
con.execute sql
rs.open sql,con,1,3
%>
<% if not rs.eof and not rs.bof then %>
<table width="861" height="71" border="1">
<tr>
<th width="64" height="35" scope="col">产品编号</th>
<th width="61" scope="col">产品名称</th>
</tr>
<tr>
<td height="28">&nbsp;<%= rs("id") %></td>
<td>&nbsp;<%= rs("name") %></td>
</tr>


每次浏览总是出现错误

请问我错在哪里,应该怎么改?谢谢!

只有本站会员才能查看附件,请 登录

[此贴子已经被作者于2007-10-10 18:52:51编辑过]

24 回复
#2
yms1232007-10-10 19:03
表单页面
<select name="idsel" size="1" onChange="document.form1.idA.value=this.options[this.selectedIndex].value;" >
<option value="1" selected>1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
<input type="hidden" name="idA" >
处理页面
<% ID=request.form("idA")%>
#3
sldtk12007-10-10 19:23
不行啊,而且这句<% ID=request.form("idA")%>应该是<% ID=request.form("idA")/%>
浏览器报错了
只有本站会员才能查看附件,请 登录

只有本站会员才能查看附件,请 登录

只有本站会员才能查看附件,请 登录

#4
yms1232007-10-10 19:29
<% ID=request.form("idA")/%>
ASP代码是<%开始%>结束
不是<%开始/%>结束
楼主是把概念混淆了。
#5
sldtk12007-10-10 19:38
不行啊
只有本站会员才能查看附件,请 登录


#6
yms1232007-10-10 20:02
<html>
<body>
<% ID=request.form("id") /%>
<%
dim con,DBPath
set con=server.CreateObject("ADODB.Connection")
DBPath=server.MapPath("data.mdb")
con.open "driver={Microsoft Access Driver(*.mdb)};dbq="&DBPath
set rs=server.CreateObject("ADODB.Recordset")
sql="select * from data"
sql=sql & "where 产品编号 like '%"& ID &"%'"
con.execute sql
rs.open sql,con,1,3
%>
<% if not rs.eof and not rs.bof then %>
<table width="861" height="71" border="1">
<tr>
<th width="64" height="35" scope="col">产品编号</th>
<th width="61" scope="col">产品名称</th>
</tr>
<tr>
<td height="28">&nbsp;<%= rs("id") %></td>
<td>&nbsp;<%= rs("name") %></td>
</tr>
这是楼主的网页这个页面的所有代码?
#7
sldtk12007-10-10 20:07

[CODE]<html>
<body>
<% ID=request.form("idA")%>
<%
dim con,DBPath
set con=server.CreateObject("ADODB.Connection")
DBPath=server.MapPath("data.mdb")
con.open "driver={Microsoft Access Driver(*.mdb)};dbq="&DBPath
set rs=server.CreateObject("ADODB.Recordset")
sql="select * from data"
sql=sql & "where 产品编号 like '%"& ID &"%'"
con.execute sql
rs.open sql,con,1,3
%>
<% if not rs.eof and not rs.bof then %>
<table width="861" height="71" border="1">
<tr>
<th width="64" height="35">产品编号</th>
<th width="61" scope="col">产品名称</th>
<th width="33" scope="col">主频</th>
<th width="49" scope="col">单双核</th>
<th width="32" scope="col">内存</th>
<th width="77" scope="col">硬盘</th>
<th width="77" scope="col">光驱</th>
<th width="77" scope="col">显卡</th>
<th width="77" scope="col">显示器</th>
<th width="77" scope="col">操作系统</th>
<th width="77" scope="col">类型</th>
<th width="84" scope="col">价格</th>
</tr>
<tr>
<td height="28">&nbsp;<%= rs("ID") %></td>
<td>&nbsp;<%= rs("name") %></td>
<td>&nbsp;<%= rs("zp") %></td>
<td>&nbsp;<%= rs("dsh") %></td>
<td>&nbsp;<%= rs("nc") %></td>
<td>&nbsp;<%= rs("yp") %></td>
<td>&nbsp;<%= rs("xk") %></td>
<td>&nbsp;<%= rs("xsq") %></td>
<td>&nbsp;<%= rs("system") %></td>
<td>&nbsp;<%= rs("lx") %></td>
<td>&nbsp;<%= rs("jg") %></td>
<td>&nbsp;<%= rs("jg1") %></td>
</tr>
</table>
</body>
</html>[/CODE]

#8
yms1232007-10-10 20:11
<% if not rs.eof and not rs.bof then %>
这个IF的End IF在哪里?
#9
sldtk12007-10-10 20:18
刚才没发完
[CODE]<% else %>
对不起,没有您要查找的数据
<%
rs.close
set rs=nothing
con.close
set con=nothing
%>
<% end if %>[/CODE]
#10
sldtk12007-10-10 20:23

刚才又出现了这个错误,请问是怎么回事?
还有这段代码<input type="hidden" name="idA" >,按钮看不见了提交不了

只有本站会员才能查看附件,请 登录

[此贴子已经被作者于2007-10-10 20:25:59编辑过]

#11
yms1232007-10-10 20:29
<html>
<body>
<% ID=request.form("idA")%>
<%
dim con,DBPath
set con=server.CreateObject("ADODB.Connection")
DBPath=server.MapPath("data.mdb")
con.open "driver={Microsoft Access Driver(*.mdb)};dbq="&DBPath
set rs=server.CreateObject("ADODB.Recordset")
sql="select * from data"
sql=sql & "where 产品编号 like '%"& ID &"%'"
con.execute sql
rs.open sql,con,1,3
%>
<% if not rs.eof and not rs.bof then %>
<table width="861" height="71" border="1">
<tr>
<th width="64" height="35">产品编号</th>
<th width="61" scope="col">产品名称</th>
<th width="33" scope="col">主频</th>
<th width="49" scope="col">单双核</th>
<th width="32" scope="col">内存</th>
<th width="77" scope="col">硬盘</th>
<th width="77" scope="col">光驱</th>
<th width="77" scope="col">显卡</th>
<th width="77" scope="col">显示器</th>
<th width="77" scope="col">操作系统</th>
<th width="77" scope="col">类型</th>
<th width="84" scope="col">价格</th>
</tr>
<tr>
<td height="28">&nbsp;<%= rs("ID") %></td>
<td>&nbsp;<%= rs("name") %></td>
<td>&nbsp;<%= rs("zp") %></td>
<td>&nbsp;<%= rs("dsh") %></td>
<td>&nbsp;<%= rs("nc") %></td>
<td>&nbsp;<%= rs("yp") %></td>
<td>&nbsp;<%= rs("xk") %></td>
<td>&nbsp;<%= rs("xsq") %></td>
<td>&nbsp;<%= rs("system") %></td>
<td>&nbsp;<%= rs("lx") %></td>
<td>&nbsp;<%= rs("jg") %></td>
<td>&nbsp;<%= rs("jg1") %></td>
</tr>
</table>
</body>
</html>
<% else %>
对不起,没有您要查找的数据
<%
rs.close
set rs=nothing
con.close
set con=nothing
%>
<% end if %>
如果是这样不应该该缺少end
#12
sldtk12007-10-10 20:32

刚才又出现了这个错误,请问是怎么回事?
还有这段代码<input type="hidden" name="idA" >,按钮看不见了提交不了

#13
yms1232007-10-10 20:36
con.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&DBPath&";Persist Security Info=False"
这样试试。
#14
sldtk12007-10-10 20:43
只有本站会员才能查看附件,请 登录

我的Acess文件名为data,里面的数据库名也是data,这样可以吗?
连数据的时候是用Acess的文件名还是直接用里面的数据库名?
我的文件都是在同一目录下的
#15
yms1232007-10-10 20:52
sql="select * from [data]"
加[]区分.
#16
sldtk12007-10-10 20:58
谢谢,已经可以跳转了,但总是查不到数据,这是为什么呢?
我的表是这样
只有本站会员才能查看附件,请 登录

还有这句代码<input type="hidden" name="idA" >,没有显示提交,要不要再加一个submit

[此贴子已经被作者于2007-10-10 21:00:58编辑过]

#17
yms1232007-10-10 21:01
where 产品编号="& ID
这样写
再不行
where 产品编号='"& ID &"'"
这样写
#18
sldtk12007-10-10 21:15
sql=sql & "where 产品编号="&ID

只有本站会员才能查看附件,请 登录


sql=sql & "where 产品编号='"& ID &"'"
只有本站会员才能查看附件,请 登录


sql=sql & "where 产品编号 like '%"&ID&"%'"


只有本站会员才能查看附件,请 登录

好像都不行
#19
yms1232007-10-10 21:52
Response.Write ID
看看这个ID返回什么数据
#20
sldtk12007-10-10 21:55
返回的是ID的值和逗号,是不是前面的下拉列表传过来的?
#21
yms1232007-10-10 22:10
ID=Replace(ID,",","")
sql="select * from [data]"
sql=sql & "where 产品编号="&ID
这样再试试。

[此贴子已经被作者于2007-10-10 22:10:17编辑过]

#22
sldtk12007-10-10 22:23
只有本站会员才能查看附件,请 登录

#23
yms1232007-10-11 22:31
ID=Replace(ID,",","")
sql="select * from [data]"
sql=sql & "where 产品编号 like '"&ID&"'"
再试试。
#24
sldtk12007-10-12 02:11
用like会跳转到else部分,它查找的值是"ID,"这个数据表里没有的找不到
用=号就会报错
#25
sldtk12007-10-12 12:54

今天终于解决了,那本破教材整得我好惨.谢谢版主提供的帮助,从中也学到不少.
还有一个问题想问,如果查询出来的结果不唯一,用什么方法动态地添加表格以显示多个数据呢?

如果用如下形式用一个表单提交,应该怎么确定哪个按钮对应哪个查询呢?

只有本站会员才能查看附件,请 登录

1