| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1423 人关注过本帖
标题:请高手更改一个实现模糊查询功能的asp,谢谢
只看楼主 加入收藏
chfmj
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2009-9-17
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:12 
请高手更改一个实现模糊查询功能的asp,谢谢
请高手帮忙,我有一个查询修改员工信息的asp,数据库字段有 用户名 姓名 权限 部门 电话等,我想要更改成任意登陆用户查询代码,能在输入框中任意输入数据库里任意字段中的内容,都可以显示全部资料,并且能支持模糊查获,比如说输入"李",就把包含"李"的所有用户名 姓名 权限 部门 电话都显示出来,不用后面的详细资料、删除和修改功能,
谢谢大侠了。

<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="Conn/conn.asp" -->
<%
'查询用户信息
Set rs_user = Server.CreateObject("ADODB.Recordset")
sql_user= "SELECT ID, UserName, purview FROM Tab_User WHERE UserName = '"&session("UserName")&"'"
rs_user.open sql_user,conn,1,3
'查询员工信息
Set rs_personnel = Server.CreateObject("ADODB.Recordset")
sql_P="SELECT ID,UserName,Name,purview,branch,job FROM Tab_User"&_
" ORDER BY UserName ASC"
rs_personnel.open sql_P,conn,1,3
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.
<html>
<head>
<title>员工信息查询</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="../style.css" rel="stylesheet">
<style type="text/css">
<!--
body {
    margin-left: 0px;
    margin-top: 0px;
}
.style10 {color: #669999}
.style11 {color: #C60001}
.STYLE13 {color: #C60001; font-size: 9pt; }
.STYLE14 {
    font-size: 9pt;
    color: #000000;
}
a:link {
    text-decoration: none;
}
a:visited {
    text-decoration: none;
}
a:hover {
    text-decoration: none;
}
a:active {
    text-decoration: none;
}
.STYLE16 {font-size: 9pt}
-->
</style></head>
<script language="javascript">
function Mycheck()
{
if(form1.branch.value=="")
{alert("请输入员工所在部门名称??");form1.branch.focus();return;}
form1.submit();
}
</script>
<body>
<table width="805" height="515" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="805" height="515" valign="top" background="../Images/main.gif"><table width="86%" height="84%" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td height="44" valign="bottom"><table width="270" height="16" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td width="29" height="16"><div align="center"><img src="../Images/isexists.gif" width="16" height="16"></div></td>
            <td width="241">员工信息维护</td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td>
        <table width="60%" height="21%" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td height="69" valign="bottom"><br>
          <table width="557" height="40"  border="0" cellpadding="-2" cellspacing="-2">
  <tr>
    <td width="7%" height="24" align="center" valign="middle">&nbsp; </td>
    <td width="20%" height="24" align="center"></td>
    <td width="4%" align="center"><img src="../images/modify.gif" width="12" height="12"></td>
    <td width="17%" align="center" class="style10"><div align="left">

    <A HREF=# class="STYLE14" onClick="Javascrip:window.open('personnel_modifyPWD.asp?ID=<%=rs_user("ID")
     %>','','width=460,height=400')">修改个人信息</a>
    </div></td>
    <td width="5%" height="24"><div align="center" class="style10"></div></td>
    <td width="30%" height="24">    </td>
    <td width="17%" height="24"><div align="center"></div></td>
  </tr>
  <tr>
    <td height="16" colspan="8"></td>
  </tr>
</table>
<table width="556" border="0" cellspacing="-2" cellpadding="-2" align="center" >
  <tr>
    <td><form action="personnel_info.asp" method="post" name="form1">
      <table width="100%" border="0" cellspacing="-2" cellpadding="-2" align="center">
        <tr>
          <td width="2%">&nbsp;</td>
          <td width="23%">&nbsp;<span class="STYLE13">请输入员工所在部门:</span></td>
          <td width="36%"><input name="branch" type="text" class="Sytle_text" id="branch">
            <input name="Submit" type="button" class="Style_button" value="搜索" onClick="Mycheck();"></td>
          <td width="12%">&nbsp;</td>
          <td width="10%">&nbsp;</td>
          <td width="17%">&nbsp;</td>
        </tr>
      </table>
    </form></td>
  </tr>
</table>        </td>
      </tr>
</table>


<table width="556" border="0" align="center" cellpadding="-2" cellspacing="-2">
  <tr>
    <td>
    <%if rs_personnel.eof then%>
    <table align="center" cellpadding="0" cellspacing="0">
      <tr><td><span class="STYLE16">无员工信息!</span></td>
      </tr></table>
    <%else%>
    <table width="97%" height="42"  border="1" align="right" cellpadding="-2" cellspacing="-2" bordercolor="#FFFFFF" bordercolorlight="#FFCCCC" bordercolordark="#FFFFFF">
      <tr>
        <td width="19%"><div align="center" class="STYLE16">用户名</div></td>
        <td width="18%"><div align="center"><span class="STYLE16">姓名</span></div></td>
        <td width="10%"><div align="center" class="STYLE16">权限</div></td>
        <td width="14%"><div align="center" class="STYLE16">部门</div></td>
        <td width="16%"><div align="center"><span class="STYLE16">职务</span></div></td>
        <td width="11%"><div align="center" class="STYLE16">详细资料</div></td>
        <td width="6%"><div align="center" class="STYLE16">修改</div></td>
        <td width="6%"><div align="center" class="STYLE16">删除</div></td>
      </tr>
       <%
        '分页
        rs_personnel.pagesize=6
        page1=CLng(Request("page1"))
        if page1<1 then page1=1
        rs_personnel.absolutepage=page1
        for i=1 to rs_personnel.pagesize
        %>
      <tr>
          <td><div class="STYLE14">&nbsp;<%=(rs_personnel("UserName"))%></div></td>
          <td><div class="STYLE14">&nbsp;<%=rs_Personnel("Name")%></div></td>
          <td><div class="STYLE14">&nbsp;<%=(rs_personnel("purview"))%></div></td>
          <td><div class="STYLE14">&nbsp;<%=(rs_personnel("branch"))%></div></td>
          <td><div class="STYLE14">&nbsp;<%=(rs_personnel("job"))%></div></td>
          <td><div align="center">
          <A HREF=# onClick="JScrip:window.open('personnel_detail.asp?ID=<%=rs_personnel("ID")
           %>','','width=556,height=310')">
           <img src="../images/detail.gif" width="16" height="17" border="0"></A></div></td>
          <td><div align="center">
          <% if trim(rs_user("purview"))="系统" then%>
              <A HREF=# onClick="JScrip:window.open('personnel_modify.asp?ID=<%=rs_personnel("ID")
               %>','','width=460,height=400')">
               <img src="../images/modify.gif" width="12" height="12" border="0"></a>
          <% else%>
              <img src="../images/modify.gif" width="12" height="12" border="0">
          <% end if %>
          </div></td>
          <td><div align="center">
            <% if trim(rs_user("purview"))="系统" then%>
              <A HREF=# onClick="JScrip:window.open('personnel_del.asp?ID=<%=rs_personnel("ID")
               %>','','width=460,height=400')">
               <img src="../images/del.gif" width="16" height="16" border="0"></a>            
          <% else%>
              <img src="../images/del.gif" width="16" height="16" border="0">
          <% end if %>
          </div></td>
      </tr>
        <% rs_personnel.movenext
        if rs_personnel.eof then exit for
        next %>
      </table></td>
  </tr>
</table>
<table width="556" border="0" align="center" cellpadding="-2" cellspacing="-2">
  <tr>
    <td><div align="right">
       <span class="STYLE16">
      <% if page1<>1 then %>
      <a href=<%=path1%>?page1=1 class="l">第一页</a>
        <a href=<%=path1%>?page1=<%=(page1-1)%> class="l">上一页</a>
        <%end if
        if page1<>rs_personnel.pagecount then %>
           <a href=<%=path1%>?page1=<%=(page1+1)%> class="l">下一页</a>
        <a href=<%=path1%>?page1=<%=rs_personnel.pagecount%> class="l">最后一页</a>
        <%end if %>
        &nbsp; </span></div></td>
  </tr>
</table>
<%end if %>
        
        &nbsp;</td>
      </tr>
    </table></td>
  </tr>
</table>
</body>
</html>
<%
rs_user.Close()
Set rs_user = Nothing
%>   
搜索更多相关主题的帖子: asp 查询 模糊 
2009-09-17 12:05
hp3325
Rank: 2
等 级:论坛游民
帖 子:29
专家分:26
注 册:2009-6-7
收藏
得分:0 
sql_user= "SELECT ID, UserName, purview FROM Tab_User"
rs_user.open sql_user,conn,1,3
'查询员工信息
Set rs_personnel = Server.CreateObject("ADODB.Recordset")
sql_P="SELECT ID,UserName,Name,purview,branch,job FROM Tab_User"&_
" ORDER BY UserName ASC"
rs_personnel.open sql_P,conn,1,3
%>
2009-09-17 12:15
孤独冷雨
Rank: 10Rank: 10Rank: 10
来 自:安徽滁州
等 级:贵宾
威 望:23
帖 子:1247
专家分:1909
注 册:2007-6-4
收藏
得分:0 
personnel_info.asp

<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="Conn/conn.asp" -->
<%
Set rs_personnel = Server.CreateObject("ADODB.Recordset")
sql_P="SELECT ID,UserName,Name,purview,branch,job FROM Tab_User like '%"&trim(request("branch"))&"%' ORDER BY UserName ASC"
rs_personnel.open sql_P,conn,1,3
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.
<html>
<head>
<title>员工信息查询</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="../style.css" rel="stylesheet">
<style type="text/css">
<!--
body {
    margin-left: 0px;
    margin-top: 0px;
}
.style10 {color: #669999}
.style11 {color: #C60001}
.STYLE13 {color: #C60001; font-size: 9pt; }
.STYLE14 {
    font-size: 9pt;
    color: #000000;
}
a:link {
    text-decoration: none;
}
a:visited {
    text-decoration: none;
}
a:hover {
    text-decoration: none;
}
a:active {
    text-decoration: none;
}
.STYLE16 {font-size: 9pt}
-->
</style></head>
<script language="javascript">
function Mycheck()
{
if(form1.branch.value=="")
{alert("请输入员工所在部门名称??");form1.branch.focus();return;}
form1.submit();
}
</script>
<body>
<table width="805" height="515" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="805" height="515" valign="top" background="../Images/main.gif"><table width="86%" height="84%" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td height="44" valign="bottom"><table width="270" height="16" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td width="29" height="16"><div align="center"><img src="../Images/isexists.gif" width="16" height="16"></div></td>
            <td width="241">员工信息维护</td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td>
        <table width="60%" height="21%" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td height="40" valign="bottom"><br>
          <table width="556" border="0" cellspacing="-2" cellpadding="-2" align="center" >
  <tr>
    <td><form action="personnel_info.asp" method="post" name="form1">
      <table width="100%" border="0" cellspacing="-2" cellpadding="-2" align="center">
        <tr>
          <td width="2%">&nbsp;</td>
          <td width="23%">&nbsp;<span class="STYLE13">请输入员工所在部门:</span></td>
          <td width="36%"><input name="branch" type="text" class="Sytle_text" id="branch"></td>
          <td width="12%"><input name="Submit" type="button" class="Style_button" value="搜索" onClick="Mycheck();"></td>
          <td width="10%">&nbsp;</td>
          <td width="17%">&nbsp;</td>
        </tr>
      </table>
    </form></td>
  </tr>
</table>        </td>
      </tr>
</table>
 
 
<table width="556" border="0" align="center" cellpadding="-2" cellspacing="-2">
  <tr>
    <td>
    <%if rs_personnel.eof then%>
    <table align="center" cellpadding="0" cellspacing="0">
      <tr><td><span class="STYLE16">无员工信息!</span></td>
      </tr></table>
    <%else%>
    <table width="97%" height="42"  border="1" align="right" cellpadding="-2" cellspacing="-2" bordercolor="#FFFFFF" bordercolorlight="#FFCCCC" bordercolordark="#FFFFFF">
      <tr>
        <td width="19%"><div align="center" class="STYLE16">用户名</div></td>
        <td width="18%"><div align="center"><span class="STYLE16">姓名</span></div></td>
        <td width="10%"><div align="center" class="STYLE16">权限</div></td>
        <td width="14%"><div align="center" class="STYLE16">部门</div></td>
        <td width="16%"><div align="center"><span class="STYLE16">职务</span></div></td>
        </tr>
       <%
        '分页
        rs_personnel.pagesize=6
        page1=CLng(Request("page1"))
        if page1<1 then page1=1
        rs_personnel.absolutepage=page1
        for i=1 to rs_personnel.pagesize
        %>
      <tr>
          <td><div class="STYLE14">&nbsp;<%=(rs_personnel("UserName"))%></div></td>
          <td><div class="STYLE14">&nbsp;<%=rs_Personnel("Name")%></div></td>
          <td><div class="STYLE14">&nbsp;<%=(rs_personnel("purview"))%></div></td>
          <td><div class="STYLE14">&nbsp;<%=(rs_personnel("branch"))%></div></td>
          <td><div class="STYLE14">&nbsp;<%=(rs_personnel("job"))%></div></td>
          </tr>
        <% rs_personnel.movenext
        if rs_personnel.eof then exit for  
        next %>
      </table></td>
  </tr>
</table>
<table width="556" border="0" align="center" cellpadding="-2" cellspacing="-2">
  <tr>
    <td><div align="right">
       <span class="STYLE16">
      <% if page1<>1 then %>
      <a href=<%=path1%>?page1=1 class="l">第一页</a>
        <a href=<%=path1%>?page1=<%=(page1-1)%> class="l">上一页</a>  
        <%end if  
        if page1<>rs_personnel.pagecount then %>
           <a href=<%=path1%>?page1=<%=(page1+1)%> class="l">下一页</a>  
        <a href=<%=path1%>?page1=<%=rs_personnel.pagecount%> class="l">最后一页</a>  
        <%end if %>
        &nbsp; </span></div></td>
  </tr>
</table>
<%end if %>
         
        &nbsp;</td>
      </tr>
    </table></td>
  </tr>
</table>
</body>
</html>
<%
rs_user.Close()
Set rs_user = Nothing
%>

这里有男女系列成人用品,有时间兄弟们来看一看.
51za.
2009-09-17 13:20
chfmj
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2009-9-17
收藏
得分:0 
非常感谢,但是,不能运行,错误类型:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[Microsoft][ODBC Microsoft Access Driver] FROM 子句语法错误。
/lll/TongXunManage/tongxun_top.asp, 第 6 行


 我想把这个"请输入员工所在部门"这个改成"请输入查询内容"
可以根据数据库中的字段内容模糊查询,任意输入姓名、性别、电话等都可查,而且不用全称,比如输入姓名中的“李”就把所有包含李的数据显示出来

[ 本帖最后由 chfmj 于 2009-9-17 20:13 编辑 ]
2009-09-17 19:57
无根泉
Rank: 2
等 级:新手上路
威 望:4
帖 子:853
专家分:0
注 册:2004-11-4
收藏
得分:0 
bvalue=trim(request("branch"))
if isnumeric(bvalue then
    csql=" 年龄 like '%"bvalue"%'" '判断是否是数字,如果是数字查询电话
else
    if len(bvalue)=1 then
        csql=" 性别='"%bvalue%"'" '如果查询条件是字符并只有一个字符的时候,查询性别
    else
        csql=" 姓名 like '%"bvalue"%'" 否则查询姓名
    end if
end if
csql=csql & " ORDER BY UserName ASC"
sql="SELECT ID,UserName,Name,purview,branch,job FROM [Tab_User] where " csql

我很菜,但我很努力!
2009-09-17 21:21
孤独冷雨
Rank: 10Rank: 10Rank: 10
来 自:安徽滁州
等 级:贵宾
威 望:23
帖 子:1247
专家分:1909
注 册:2007-6-4
收藏
得分:0 
上面那个SQL语句错了!你把它换成。
sql_P="SELECT ID,UserName,Name,purview,branch,job FROM Tab_User where UserName like '%"&trim(request("branch"))&"%' or Name like '%"&trim(request("branch"))&"%' or like '%"&trim(request("branch"))&"%' or branch like '%"&trim(request("branch"))&"%' or job like '%"&trim(request("branch"))&"%' order BY UserName ASC"

这里有男女系列成人用品,有时间兄弟们来看一看.
51za.
2009-09-18 09:56
chfmj
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2009-9-17
收藏
得分:0 
还是不能运行,错误类型:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[Microsoft][ODBC Microsoft Access Driver] 语法错误 (操作符丢失) 在查询表达式 'UserName like '%%' or Name like '%%' or like '%%' or branch like '%%' or job like '%%'' 中。
/lll/UersManage/personnel_top.asp, 第 6 行
天啊,我晕了
2009-09-18 22:46
chfmj
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2009-9-17
收藏
得分:0 
还是不能运行,错误类型:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[Microsoft][ODBC Microsoft Access Driver] 语法错误 (操作符丢失) 在查询表达式 'UserName like '%%' or Name like '%%' or like '%%' or branch like '%%' or job like '%%'' 中。
/lll/UersManage/personnel_top.asp, 第 6 行
天啊,我晕了
2009-09-18 22:46
孤独冷雨
Rank: 10Rank: 10Rank: 10
来 自:安徽滁州
等 级:贵宾
威 望:23
帖 子:1247
专家分:1909
注 册:2007-6-4
收藏
得分:0 
把你文件带上数据库压个包传上来!帮你看一下!

这里有男女系列成人用品,有时间兄弟们来看一看.
51za.
2009-09-19 10:04
chfmj
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2009-9-17
收藏
得分:0 
回复 9楼 孤独冷雨
老大,你太好了,拜托,拜托.

源程序有两个,一个是查询的界面personnel_top.asp,一个是输入出的界面文件personnel_bottom.asp,数据库文件中表是Tab_User
UersManage.rar (20.04 KB)


[ 本帖最后由 chfmj 于 2009-9-19 23:55 编辑 ]
2009-09-19 23:50
快速回复:请高手更改一个实现模糊查询功能的asp,谢谢
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.033462 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved