当前位置: 首页 > 图文教程 > 网络编程 > ASP > 教程/ASP 十天学会ASP之第六天

ASP
ASP调用ORACLE存储过程并返回结果集
用ASP实现网页BBS
关于Global.asa文件的深入研究与session变量失效提示的具体方法
简易ASP+注册系统
防护手册:如何防止ASP木马在服务器上运行
用Visual Basic实现多画面播放功能之二
如何增强ASP程序性能(1)
如何增强ASP程序性能(2)
如何增强ASP程序性能(3)
ASP备份数据库
二十八条改善 ASP 性能和外观的技巧
在Form域中Post大于100K的数据
如何使用ASP制作模似动态生长的表单?
Microsoft IIS 真的如此「不安全」吗?(1)
Microsoft IIS 真的如此「不安全」吗?(2)
Microsoft IIS 真的如此「不安全」吗?(3)
Microsoft IIS 真的如此「不安全」吗?(4)
Microsoft IIS 真的如此「不安全」吗?(5)
关于页面和代码分离
ServerVariables 对路径的操作

教程/ASP 十天学会ASP之第六天


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-14   浏览: 165 ::
收藏到网摘: n/a

  学习目的:学会数据库的基本操作2(查询记录)

  在第四天中我们有这样一个程序:

  <%
  set conn=server.createobject("adodb.connection")
  conn.open "driver={microsoft access driver (*.mdb)};dbq="&server.mappath("example3.mdb")
  exec="select * from guestbook"
  set rs=server.createobject("adodb.recordset")
  rs.open exec,conn,1,1
  %>
  
  我们查询的是所有的记录,但是我们要修改、删除记录的时候不可能是所有记录,所有我们要学习检索合适的记录。先看一条语句:

  a="张三"
  b=111
  exec="select * from guestbook where name='"+a+"'and tel="+b
  
  where后面加上的是条件,与是and,或是or,我想=,<=,>=,<,>的含义大家都知道吧。这句话的意思就是搜索name是张三的,并且电话是111的记录。还有一点就是如果要搜索一个字段里面是不是包含一个字符串就可以这么写:where instr(name,a)也就是搜索name里面有a(张三)这个字符串的人。

  我这里的a,b,是常量,大家可以让a,b是表单提交过来的变量,这样就可以做一个搜索了。

  下面大家看看这个代码,理解一下:

  <form name="form1" method="post" action="example6.asp">
  搜索:<br>
  name =
  <input type="text" name="name">
  and tel=
  <input type="text" name="tel">
  <br>
  <input type="submit" name="Submit" value="提交">
  <input type="reset" name="Submit2" value="重置">
  </form>

  example6.asp:
  <%
  name=request.form("name")
  tel=request.form("tel")
  set conn=server.createobject("adodb.connection")
  conn.open "driver={microsoft access driver (*.mdb)};dbq="&server.mappath("example3.mdb")
  exec="select * from guestbook where name='"+name+"' and tel="+tel
  set rs=server.createobject("adodb.recordset")
  rs.open exec,conn,1,1
  %>
  <html>
  <head>
  <title>无标题文档</title>
  <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
  <table width="100%" border="0" cellspacing="0" cellpadding="0">
  <%
  do while not rs.eof
  %><tr>
  <td><%=rs("name")%></td>
  <td><%=rs("tel")%></td>
  <td><%=rs("message")%></td>
  <td><%=rs("time")%></td>
  </tr>
  <%
  rs.movenext
  loop
  %>
  </table>
  </body>
  </html>

  今天实际上就讲了一个where,大家回去做做试验,把instr()做进去,明天见!