非常简单的一个查询问题,等于白送分!

qq4999300 2009-06-18 02:12:01
首先贴一个index.asp的页面代码:
<form  name="form2" action="search.asp">
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><div align="center">条件查询:
<select name="select">
<option value="name" selected>按姓名</option>
<option value="inno">按住院号</option>
<option value="intime">按住院时间</option>
<option value="outtime">按出院时间</option>
</select>
关键字:
<input name="kws" type="text" size="18" />
<input type="submit" name="Submit" value="提交" />
</div>
</label></td>
</tr>
</table>
</form>


再来一个search.asp的页面代码:

<%
kws=trim(request.Form("kws"))
sel=request.Form("select")
set rs=server.CreateObject("ADODB.RecordSet")
rs.open "select * from user where name='"&kws&"'",conn,1,1

%>
<%
do while not rs.eof
%>
</p>
<table width="800" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="132"><div align="center">住院号</div></td>
<td width="133"><div align="center">姓名</div></td>
<td width="133"><div align="center">性别</div></td>
<td width="133"><div align="center">年龄</div></td>
<td width="133"><div align="center">入院时间</div></td>
<td width="133"><div align="center">出院时间</div></td>
</tr>
</table>
<table width="800" border="0" cellspacing="0" cellpadding="0">
<tr>
<a href="show.asp?id=<%=rs("id")%>">
<td width="132"><div align="center"><%=rs("inno")%></div></td>
<td width="133"><div align="center"><%=rs("name")%></div></td>
<td width="133"><div align="center"><%=rs("sex")%></div></td>
<td width="133"><div align="center"><%=rs("age")%></div></td>
<td width="133"><div align="center"><%=rs("intime")%></div></td>
<td width="133"><div align="center"><%=rs("outtime")%></div></td>
</a> </tr>
<%
rs.movenext
loop
%>
<%if rs.eof and rs.bof then%>
<p>没有找到记录</p></br></br>
<%end if%>
</table>


一看代码就知道我要做下拉列表和关键字的查询,我的这句程序rs.open "select * from user where name='"&kws&"'",conn,1,1 代码没写正确,也没写全,后面不知道该怎么写,请教高人指点如何同时可以让下来列表和关键字同时查询。
...全文
44 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq4999300 2009-06-18
  • 打赏
  • 举报
回复
我不会用过程啊,就用SQL语句能解决吗?
chowyi 2009-06-18
  • 打赏
  • 举报
回复


用过程吧

create proc dbo.yourprocName
@yourcolname varchar(255),
@yourkey varchar(255)
as
begin
declare @sqlstr varchar(8000)
set nocount on
set @sqlstr='select * from user where @yourcolname=@yourkey'
exec(@sqlstr)
end
claro 2009-06-18
  • 打赏
  • 举报
回复
jf
qq4999300 2009-06-18
  • 打赏
  • 举报
回复
我是新手,还是不大明白,请看看我代码,我这里要实现是选择下拉列表的值之后,自动对应查询条件。
我就这样写了rs.open "select * from user where '"&sel&"'='"&kws&"'" ,conn,1,1
这样对不对????如果是正确的话,我什么也查不到。不正确,错在哪里?请指教!
JonasFeng 2009-06-18
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 jwdream2008 的回复:]
VB.NET code"select * from user where '"&ColumnName&"'='"&Key&"'"


ColumnName:所选条件的列名(如按姓名即为Name列)
Key:为查询条件:(比如名字为:张三)
[/Quote]

UP
qq4999300 2009-06-18
  • 打赏
  • 举报
回复
请教 在我提供的以上代码中该如何写?是这样的吗?
rs.open "select * from user where '"&sel&"'='"&kws&"'" ,conn,1,1

但是这样写了之后,程序倒不出错,就是什么都查询不到
忘了说明一点,在index.asp中,的
<form  name="form2" action="search.asp">
实际是:
<form  name="form2" method="post" action="search.asp">


求教高人还是给我一个现成的套用参数的代码吧!
jwdream2008 2009-06-18
  • 打赏
  • 举报
回复
"select * from user where '"&ColumnName&"'='"&Key&"'" 

ColumnName:所选条件的列名(如按姓名即为Name列)
Key:为查询条件:(比如名字为:张三)
jwdream2008 2009-06-18
  • 打赏
  • 举报
回复
"select * from user where '"&"'ColumnName='"&Key&"'" 

34,872

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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