Learning purposes: Learn the basic operation of the database 2 (Query records)
on the fourth day we have this program:
<%
Set Conn=server.createobject ("Adodb.connection")
Conn.Open "Driver={microsoft Access Driver (*.mdb)};d bq=" &server.mappath ("Example3.mdb")
Exec= "SELECT * FROM Guestbook"
Set Rs=server.createobject ("Adodb.recordset")
Rs.Open exec,conn,1,1
%>
We're looking at all the records, but we're not going to be able to get all the records when we want to modify or delete the records, all of us have to learn to retrieve the right records. First look at a statement:
A= "John"
b=111
Exec= "SELECT * from guestbook where name= '" +a+ "' and Tel= ' +b
Where the following is the condition, with and, or, I think everyone knows the meaning of =,<=,>=,<,>. The search name is John, and the phone is a 111 record. The other thing is if you're searching for a field that contains a string, you can write this: where InStr (Name,a) is the person who searches for the string of a (John) in name.
my a,b here, is a constant, you can let A,b is the form submitted to the variable, so you can do a search.
Let's take a look at this code to understand:
<form name= "Form1" method= "Post" action= "example6.asp" >
Search:<br>
Name =
<input type= "text" name= "name" >
and tel=
<input type= "Text" name= "Tel" >
<br>
<input type= "Submit" name= "Submission" value= "submitted" >
<input type= "reset" name= "Submit2" value= "reset" >
</form>
Example6.asp:
<%
Name=request.form ("name")
Tel=request.form ("tel")
Set Conn=server.createobject ("Adodb.connection")
Conn.Open "Driver={microsoft Access Driver (*.mdb)};d bq=" &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
%>
<title> Untitled Document </title>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<body bgcolor= "#FFFFFF" text= "#000000" >
<table width= "100%" border= "0" cellspacing= "0" cellpadding= "0" >
<%
Do as 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>
today actually said a where, we go back to do the experiment, put InStr () to do in, see you tomorrow!