asp通过文本框条件查询

wo331847512 2010-07-10 11:08:25
<%
dim rs_sqlSelect
dim str_dataConn
dim str_sqlSelect

set str_dataConn = server.createObject("adodb.connection")
set rs_sqlSelect = server.createObject("adodb.recordset")
str_dataConn.open "driver={SQL Server};server=7E31BQPBY5LO134\SQLEXPRESS;uid=sa;pwd=123456789;database=UserInfo"
if text1.text="" then
str_sqlSelect = "select * from usr"
else
str_sqlSelect = "select * from usr where usrnam like '%text1.text%'"
end if
rs_sqlSelect.open str_sqlSelect, str_dataConn, 1, 1
do while not rs_sqlSelect.eof
i=0
%>
<tr>
<td height="30" align="center" class="td_line_col_FFFFFF">
<%=rs_sqlSelect("usrrnm")%>
</td>
<td height="30" align="center" class="td_line_col_FFFFFF">
<%=rs_sqlSelect("usrdnm")%>
</td>
<td height="30" align="center" class="td_line_col_FFFFFF">
<%=rs_sqlSelect("usrdcd")%>
</td>
<td height="30" align="center" class="td_line_col_FFFFFF">
<%=rs_sqlSelect("usrbtd")%>
</td>
</tr>
<%
i=i+1
rs_sqlSelect.MoveNext
loop
rs_sqlSelect.close
set rs_sqlSelect = nothing
set str_dataConn = nothing
%>






刚一加载页面时提取出数据 ,我想页面打开后在文本框里输入文字点击按钮从新查询,提示对象错误 ,小弟刚学,麻烦各位给看看
...全文
102 点赞 收藏 21
写回复
21 条回复
切换为时间正序
请发表友善的回复…
发表回复
ChinaXtHuLang 2010-07-10
接上面的
str_sqlSelect = "select * from usr where usrnam like '%"&text1.value&"%'"


改成:
str_sqlSelect = "select * from usr where 1=1"
If text1<>"" Then
str_sqlSelect = str_sqlSelect &" And usrnam like '%"&text1&"%'"
End If
回复
ChinaXtHuLang 2010-07-10
<script type="text/javascript">
function chaxun(){
window.href("search.asp?text1='+text1+'");
}

</script>

<input type="text" id="text1" name="text1" value="" />


然在:
search.asp页面接收:
text1 = Trim(request("text1"))

回复
wo331847512 2010-07-10
7楼的,按你的那么改能通过了,可是我在文本框里输入查询文字 ,点查询没效果 ,数据没变 ,怎么改,麻烦了
回复
猜我是几娃 2010-07-10
if request.form("text1")="" then
回复
wo331847512 2010-07-10
那怎么对文本框的内容进行判断 麻烦给写一下
回复
wo331847512 2010-07-10
<html>
<head>
<title></title>
<script type="text/javascript">
function chaxun(){
window.href("search.asp");
}

</script>

<style type="text/css">
.td_line_col_FFFFFF
{
border: 1px black solid;
}
</style>
</head>
<body>
<table width="966" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td>
<input type="text" id="text1" value="" />
<input type="button" value="查询" onclick="chaxun();" />
</td>
</tr>
<%
dim rs_sqlSelect
dim str_dataConn
dim str_sqlSelect

set str_dataConn = server.createObject("adodb.connection")
set rs_sqlSelect = server.createObject("adodb.recordset")
str_dataConn.open "driver={SQL Server};server=7E31BQPBY5LO134\SQLEXPRESS;uid=sa;pwd=123456789;database=UserInfo"
'if text1.value="" then
'str_sqlSelect = "select * from usr"
'else
str_sqlSelect = "select * from usr where usrnam like '%"&text1.value&"%'"
'end if
rs_sqlSelect.open str_sqlSelect, str_dataConn, 1, 1
do while not rs_sqlSelect.eof
i=0
%>
<tr>
<td height="30" align="center" class="td_line_col_FFFFFF">
<%=rs_sqlSelect("usrrnm")%>
</td>
<td height="30" align="center" class="td_line_col_FFFFFF">
<%=rs_sqlSelect("usrdnm")%>
</td>
<td height="30" align="center" class="td_line_col_FFFFFF">
<%=rs_sqlSelect("usrdcd")%>
</td>
<td height="30" align="center" class="td_line_col_FFFFFF">
<%=rs_sqlSelect("usrbtd")%>
</td>
</tr>
<%
i=i+1
rs_sqlSelect.MoveNext
loop
rs_sqlSelect.close
set rs_sqlSelect = nothing
set str_dataConn = nothing
%>
</table>
</body>
</html>










页面上就是这样的, 麻烦各位给看看
回复
lzp4881 2010-07-10
if text1.text="" then
ASP不是asp.net,不能直接取文件框的值
回复
wo331847512 2010-07-10
if text1.text="" then
到这儿就提示对象不存在

跳不到这条sql,是不是我的文本框有问题
回复
majihui 2010-07-10
、学习,帮顶
回复
猜我是几娃 2010-07-10
str_sqlSelect = "select * from usr where usrnam like '%text1.text%'"
改为:
str_sqlSelect = "select * from usr where usrnam like '%"&text1.text&"%'"
回复
wo331847512 2010-07-10
可以了 太感谢了
回复
ChinaXtHuLang 2010-07-10
不用js试试:
<%
dim str_dataConn
set str_dataConn = server.createObject("adodb.connection")
str_dataConn.open "driver={SQL Server};server=.\SQLEXPRESS;uid=sa;pwd=123456789;database=UserInfo"
%>
<html>
<head>
<style type="text/css">
.td_line_col_FFFFFF {
border: 1px black solid;
}
</style>
</head>
<body>
<%
oAction = Trim(Request("oAction"))
Select Case oAction
Case "list"
Call list()
Case Else
Call list()
End Select
Sub list()
%>
<table width="966" border="0" align="center" cellpadding="0" cellspacing="0">
<form action="" method="post">
<tr>
<td><input type="text" id="text1" name="text1" value="" />
<input type="submit" value="查询"/></td>
</tr>
</form>
<%
text1 = Trim(request("text1"))
dim rs_sqlSelect

dim str_sqlSelect
set rs_sqlSelect = server.createObject("adodb.recordset")
str_sqlSelect = "select * from usr where 1=1"
If text1<>"" Then
str_sqlSelect = str_sqlSelect &" And usrnam like '%"&text1&"%'"
End If
rs_sqlSelect.open str_sqlSelect, str_dataConn, 1, 1
do while not rs_sqlSelect.eof
i=0
%>
<tr>
<td height="30" align="center" class="td_line_col_FFFFFF"><%=rs_sqlSelect("usrrnm")%></td>
<td height="30" align="center" class="td_line_col_FFFFFF"><%=rs_sqlSelect("usrdnm")%></td>
<td height="30" align="center" class="td_line_col_FFFFFF"><%=rs_sqlSelect("usrdcd")%></td>
<td height="30" align="center" class="td_line_col_FFFFFF"><%=rs_sqlSelect("usrbtd")%></td>
</tr>
<%
i=i+1
rs_sqlSelect.MoveNext
loop
rs_sqlSelect.close
set rs_sqlSelect = nothing
set str_dataConn = nothing
%>
</table>
<%
End Sub
%>
</body>
</html>
回复
wo331847512 2010-07-10
是不是我的代码其他部分有问题吧
回复
wo331847512 2010-07-10
还是不行 麻烦你了 呵呵
回复
ChinaXtHuLang 2010-07-10
不好意思。少个'
再试试
window.href('search.asp?text1='+sd+'');
回复
wo331847512 2010-07-10
还是不行 就提示网页有错误
回复
ChinaXtHuLang 2010-07-10
window.href("search.asp?text1="+sd+"");
改成:
window.href('search.asp?text1='+sd+');
回复
wo331847512 2010-07-10
<html>
<head>
<script type="text/javascript">
function chaxun(){
var sd = document.getElementById('text1').value;
window.href("search.asp?text1="+sd+"");
}
</script>

<style type="text/css">
.td_line_col_FFFFFF
{
border: 1px black solid;
}
</style>
</head>
<body>
<table width="966" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td>
<input type="text" id="text1" name="text1" value="" />
<input type="button" value="查询" onclick="chaxun();" />
</td>
</tr>
<%
text1 = Trim(request("text1"))
dim rs_sqlSelect
dim str_dataConn
dim str_sqlSelect
set str_dataConn = server.createObject("adodb.connection")
set rs_sqlSelect = server.createObject("adodb.recordset")
str_dataConn.open "driver={SQL Server};server=.\SQLEXPRESS;uid=sa;pwd=123456789;database=UserInfo"
str_sqlSelect = "select * from usr where 1=1"
If text1<>"" Then
str_sqlSelect = str_sqlSelect &" And usrnam like '%"&text1&"%'"
End If
rs_sqlSelect.open str_sqlSelect, str_dataConn, 1, 1
do while not rs_sqlSelect.eof
i=0
%>
<tr>
<td height="30" align="center" class="td_line_col_FFFFFF">
<%=rs_sqlSelect("usrrnm")%>
</td>
<td height="30" align="center" class="td_line_col_FFFFFF">
<%=rs_sqlSelect("usrdnm")%>
</td>
<td height="30" align="center" class="td_line_col_FFFFFF">
<%=rs_sqlSelect("usrdcd")%>
</td>
<td height="30" align="center" class="td_line_col_FFFFFF">
<%=rs_sqlSelect("usrbtd")%>
</td>
</tr>
<%
i=i+1
rs_sqlSelect.MoveNext
loop
rs_sqlSelect.close
set rs_sqlSelect = nothing
set str_dataConn = nothing
%>
</table>
</body>
</html>
还是不行 没效果 数据没变
回复
ChinaXtHuLang 2010-07-10
str_sqlSelect = str_sqlSelect &" And usrnam like '%"&name&"%'"

改成:
str_sqlSelect = str_sqlSelect &" And usrnam like '%"&text1&"%'"
回复
ChinaXtHuLang 2010-07-10
function chaxun(){
window.href("search.asp?name='+text1+'");
}

改成:
function chaxun(){
var sd = document.getElementById('text1').value;
window.href("search.asp?text1="+sd+"");
}

试试
回复
发动态
发帖子
ASP
创建于2007-09-28

2.8w+

社区成员

ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
申请成为版主
社区公告
暂无公告