2009年3月7日星期六

十天学会ASP之第六天

学习目的:学会数据库的基本操作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是表单提交过来的变量,这样就可以做一个搜索了。
下面大家看看这个代码,理解一下:

搜索:

name =

and tel=








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


无标题文档




<%
do while not rs.eof
%>





<%
rs.movenext
loop
%>
<%=rs("name")%> <%=rs("tel")%> <%=rs("message")%> <%=rs("time")%>




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


-

没有评论:

wholesale retail company from china

achinaseller.com is a professional wholesale retail company, having our own factory with 5 years of wholesale retail experience. Achinaseller.com is also cooperating closely with many factories, so the price that we offer to the consumer is directly from the Chinese Factory. Without leaving your home, you could order your own products at achinaseller.com at the lowest price.
We service over 100,000 registered buyers, delivering to virtually every country in the world. Our warehouse and office are staffed by a young team of Chinese and Western staff.
Happy AchinaSeller buyers include frequent wholesale importers, famous ecommerce websites, eBay powersellers, retail shops and startup home import businesses. On a daily basis, we serve corporate buyers, drop-ship experts, home business Moms, and small bussiness wholesaler