Knowledge required by each ASP programmer

Source: Internet
Author: User
Program | programmer Database connection:
<%
Set Conn=server.createobject ("Adodb.connection")
Conn.Open "Driver={microsoft Access Driver (*.mdb)};d bq=" &server.mappath ("Database name")
%>


To open a database:
Exec= "SELECT * From database table"
Set Rs=server.createobject ("Adodb.recordset")
Rs.Open exec,conn,1,1
Parameter 1,1 to read

Read content format: <%=rs ("field")%>

To add a record handler:
<%
Set Conn=server.createobject ("Adodb.connection")
Conn.Open "Driver={microsoft Access Driver (*.mdb)};d bq=" &server.mappath ("Database name")
Name=request.form (field) name,tel,message The field value that is set for submitting the form
Tel=request.form ("field")
Message=request.form ("field")
exec= insert into table name (field) VALUES (' + field + ') ' multiple separated by commas
Conn.execute exec commits using execute
Conn.close
Set conn=nothing
%>

Search handler:
<%
Name=request.form (field) Name,tel The field value that is set for submitting the form
Tel=request.form ("field")
Set Conn=server.createobject ("Adodb.connection")
Conn.Open "Driver={microsoft Access Driver (*.mdb)};d bq=" &server.mappath ("Database name")
Exec= "SELECT * from table where name= '" + Field + "' and tel=" + field
Set Rs=server.createobject ("Adodb.recordset")
Rs.Open exec,conn,1,1
%>
' Content exported from page search to
<%
Do as not rs.eof
%><tr>
<td><%=rs ("name")%></td>
<td><%=rs ("tel")%></td>
<td><%=rs ("Time")%></td>
</tr>
<%
Rs.movenext
Loop
%>

To delete a record handler:
<%
Set Conn=server.createobject ("Adodb.connection")
Conn.Open "Driver={microsoft Access Driver (*.mdb)};d bq=" &server.mappath ("Database name")
exec= "Delete * from table name where number =" &request.form ("id")
Conn.execute exec
%>


To modify a record handler:
<%
Set Conn=server.createobject ("Adodb.connection")
Conn.Open "Driver={microsoft Access Driver (*.mdb)};d bq=" &server.mappath ("Database name")
Exec= "SELECT * from table name where number =" &request.form ("id")
Set Rs=server.createobject ("Adodb.recordset")
Rs.Open exec,conn,1,3 ' 1,3 for modification meaning
RS ("name") =request.form ("field") ' Name,tel,message the field value set for submitting the form
RS ("tel") =request.form ("field")
RS ("message") =request.form ("field")
Rs.update
Rs.close
Set rs=nothing
Conn.close
Set conn=nothing
%>
Modify Record Execution program: enter ID number page >>> export relative ID data >>>>>> directly modified handler

Background Login Handler Example:
<%
Dim Name,password
Name=request.form ("name")
Password=request.form ("password")
Dim exec,conn,rs
exec= "Select *from table name where (name= ' & Field & ' and Password= '" & Field & "')
Set Conn=server.createobject ("Adodb.connection")
Conn.Open "Driver={microsoft Access Driver (*.mdb)};d bq=" &server.mappath ("Database name")
Set Rs=server.createobject ("Adodb.recordset")
Rs.Open Exec,conn
If not rs.eof then
Rs. Close
Conn. Close
Session ("checked") = "yes"
Session ("check") = ' right '
Response. Redirect "Index.asp"
Else
Session ("checked") = "No"
Session ("check") = "wrong"
Response. Redirect "Login.asp"
End If
%>

Each background page plus:
<%if not session ("checked") = "yes" Then ' session defines a checked string variable
Response. Redirect "Login.asp"
Else
%>



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.