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
%>






刚一加载页面时提取出数据 ,我想页面打开后在文本框里输入文字点击按钮从新查询,提示对象错误 ,小弟刚学,麻烦各位给看看
...全文
182 21 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
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+"");
}

试试
加载更多回复(1)

28,409

社区成员

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

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