如何根据输入的ID号查询出相应的记录.万分感谢

sunhonglei2004 2008-03-06 11:41:16
如何根据输入的ID号查询出相应的记录.我的代码入下,新手上路,万分感谢

第一个页面
<%
dim id
id=request.form("id1")
s2Sql="select * from tb "
set rs=server.CreateObject("ADODB.Recordset")
rs.open s2Sql,conn,1,1
%>
<form id="form1" name="form1" method="post" action="">
<p>
<a href="insert.asp" class="STYLE3">插入记录</a></p>
<p align="center">请输入要查询用户的id
<input name="id1" type="text" id="id1" />
 <a href="index_cha.asp?id1=<%=rs("id")%>" target="_blank">查询</a> </p>

第二个页面index_cha.asp
<%
dim id
id=request.querystring("id1")
s2Sql="select * from tb where id like '" &id&"'"
set rs=server.CreateObject("ADODB.Recordset")
rs.open s2Sql,conn,1,1
%>
...全文
742 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
zouxiangwen 2008-03-06
  • 打赏
  • 举报
回复
<%
dim cmdTemp
Set cmdTemp = Server.CreateObject("ADODB.Command")
set rs = server.CreateObject ("adodb.recordset")
if request("号码字段1")="" then
sql="select * from [表] order by id desc"
else
sql="select * from [表] where 模湖字段1 like '%"&request("号码字段1")&"%'or 模湖字段2落like '%"&request("码字段1")&"%'"
end if
cmdTemp.CommandText = sql
cmdTemp.CommandType = 1
Set cmdTemp.ActiveConnection = conn
rs.Open cmdTemp,,1,1
set cmdTemp=nothing
If rs.eof or rs.bof Then
response.write "<br>没有找到号码!"
response.end
end if
%>


放在要查询的地方。
<form method="POST" action="">快速查找用户:<input type="text" name="号码字段11" size="10">
<input border="0" src="../img/x_1.gif" name="I1" type="image">(输入<font color="#FF0000">用户名</font>或<font color="#FF0000">企业名称</font>,可以模糊搜索)
</form>
CoffeeShop 2008-03-06
  • 打赏
  • 举报
回复
有一点你为什么要用LIKE? 这找出来的记录不是唯一的 应该用等于

第二个页面index_cha.asp
<%
dim id
id=cint(request("id1"))
s2Sql="select * from tb where id =" &id
set rs=server.CreateObject("ADODB.Recordset")
rs.open s2Sql,conn,1,1
%>
cnchart 2008-03-06
  • 打赏
  • 举报
回复
s2Sql="select * from tb where id=" &cint(id)
CoffeeShop 2008-03-06
  • 打赏
  • 举报
回复
第二个页面index_cha.asp
<%
dim id
id=request.querystring("id1")
s2Sql="select * from tb where id like '%" &id&"'%"
set rs=server.CreateObject("ADODB.Recordset")
rs.open s2Sql,conn,1,1
%>
sunhonglei2004 2008-03-06
  • 打赏
  • 举报
回复
数据库中ID为INT 型,
网页中输入ID的地方为一单行文本框.

  • 打赏
  • 举报
回复
你的ID是什么类型的???
自动编号?数字?文本???
sunhonglei2004 2008-03-06
  • 打赏
  • 举报
回复
楼上,不行啊,
cnchart 2008-03-06
  • 打赏
  • 举报
回复
id如为整型,不必加引号

s2Sql="select * from tb where id=" &id就行了
cnchart 2008-03-06
  • 打赏
  • 举报
回复
第一个页面
<form id="form1" name="form1" method="post" action="index_cha.asp">
<p>
<a href="insert.asp" class="STYLE3"> 插入记录 </a> </p>
<p align="center"> 请输入要查询用户的id
<input name="id" type="text" id="id" />
  <input type="submit" value="查询"> 查询</p> </form>

第二个页面index_cha.asp
<%
dim id
id=request("id")
s2Sql="select * from tb where id like " &id
set rs=server.CreateObject("ADODB.Recordset")
rs.open s2Sql,conn,1,1
......
%>
木头是猫 2008-03-06
  • 打赏
  • 举报
回复
<a href="index_cha.asp?id1= <%=rs("id")%> " target="_blank"> 查询 </a> </p>


问题出在这个 <%=rs("id")%>上 这个值哪里来?

上面的
s2Sql="select * from tb "
set rs=server.CreateObject("ADODB.Recordset")
rs.open s2Sql,conn,1,1
并没有特指某条数据,而是搜索所有数据
  • 打赏
  • 举报
回复
你用的是href传过去
又不带参数,能获取值?
你想用文本框传值你得用表单形式传递过去!
sunhonglei2004 2008-03-06
  • 打赏
  • 举报
回复
楼上的各位大侠,我觉得现在的问题是ID根本就传不到index_cha.asp这个页面,所以查不出来,

28,390

社区成员

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

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