Tutorial/asp 10 days to learn the sixth day of ASP

Source: Internet
Author: User
Tags reset string access

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!



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.