Basic knowledge required by ASP beginners

Source: Internet
Author: User

We all know that,ASPIs the abbreviation of Active Server Page, meaning "dynamic Server Page ". ASP is an application developed by Microsoft to replace CGI script programs. It can interact with databases and other programs and is a simple and convenient programming tool. The following describes some basic knowledge for your reference.

1. database connection:

Reference content is as follows:

 
 
  1. <%
  2. Set conn = server. createobject ("adodb. connection ")
  3. Conn. open "driver = {microsoft access driver (*. mdb)}; dbq =" & server. mappath ("Database Name ")
  4. %>

2. Open the database:

Reference content is as follows:

 
 
  1. Exec = "select * from database table"
  2. Set rs = server. createobject ("adodb. recordset ")
  3. Rs. open exec, conn, 1, 1

Parameter 1, 1 is read

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

3. Add a record handler:

Reference content is as follows:

 
 
  1. <%
  2. Set conn = server. createobject ("adodb. connection ")
  3. Conn. open "driver = {microsoft access driver (*. mdb)}; dbq =" & server. mappath ("Database Name ")
  4. Name = request. form ("field") name, tel, message is the field value set in the submission form
  5. Tel = request. form ("field ")
  6. Message = request. form ("field ")
  7. Exec = "insert into Table Name (field) values ('" + field + "')" separated by commas
  8. Conn.exe cute exec use execute to submit
  9. Conn. close
  10. Set conn = nothing
  11. %>

4. Search handler:

Reference content is as follows:

 
 
  1. <%
  2. Name = request. form ("field") name, tel is the field value set for the submission form
  3. Tel = request. form ("field ")
  4. Set conn = server. createobject ("adodb. connection ")
  5. Conn. open "driver = {microsoft access driver (*. mdb)}; dbq =" & server. mappath ("Database Name ")
  6. Exec = "select * from table where name = '" + field + "' and tel =" + Field
  7. Set rs = server. createobject ("adodb. recordset ")
  8. Rs. open exec, conn, 1, 1
  9. %>
  10. 'The content found on the page is exported
  11. <%
  12. Do while not rs. eof
  13. %> <Tr>
  14. <Td> <% = rs ("name") %> </td>
  15. <Td> <% = rs ("tel") %> </td>
  16. <Td> <% = rs ("time") %> </td>
  17. </Tr>
  18. <%
  19. Rs. movenext
  20. Loop
  21. %>

5. Delete record handler:

Reference content is as follows:

 
 
  1. <%
  2. Set conn = server. createobject ("adodb. connection ")
  3. Conn. open "driver = {microsoft access driver (*. mdb)}; dbq =" & server. mappath ("Database Name ")
  4. Exec = "delete * from table name where id =" & request. form ("id ")
  5. Conn.exe cute exec
  6. %>

6. Modify the record handler:

Reference content is as follows:

 
 
  1. <%
  2. Set conn = server. createobject ("adodb. connection ")
  3. Conn. open "driver = {microsoft access driver (*. mdb)}; dbq =" & server. mappath ("Database Name ")
  4. Exec = "select * from table name where id =" & request. form ("id ")
  5. Set rs = server. createobject ("adodb. recordset ")
  6. Rs. open exec, conn, 1, 3 '1, 3
  7. Rs ("name") = request. form ("field") 'name, tel, message is the field value set in the submission form
  8. Rs ("tel") = request. form ("field ")
  9. Rs ("message") = request. form ("field ")
  10. Rs. update
  11. Rs. close
  12. Set rs = nothing
  13. Conn. close
  14. Set conn = nothing
  15. %>

Modify the record execution program: Enter the ID number page> export the corresponding ID data >>>> directly modify the processing program

VII. Example of background login handler:

Reference content is as follows:

 
 
  1. <%
  2. Dim name, password
  3. Name = request. form ("name ")
  4. Password = request. form ("password ")
  5. Dim exec, conn, rs
  6. Exec = "select * from table name where (name = '" & field & "' and password = '" & field &"')"
  7. Set conn = server. createobject ("adodb. connection ")
  8. Conn. open "driver = {microsoft access driver (*. mdb)}; dbq =" & server. mappath ("Database Name ")
  9. Set rs = server. createobject ("adodb. recordset ")
  10. Rs. open exec, conn
  11. If not rs. eof then
  12. Rs. Close
  13. Conn. Close
  14. Session ("checked") = "yes"
  15. Session ("check") = "right"
  16. Response. Redirect "index. asp"
  17. Else
  18. Session ("checked") = "no"
  19. Session ("check") = "wrong"
  20. Response. Redirect "login. asp"
  21. End if
  22. %>

Add:

 
 
  1. <% If not session ("checked") = "yes" then' the session defines a checked string variable.
  2. Response. Redirect "login. asp"
  3. Else
  4. %>

I hope that the introduction of the Basic ASP knowledge can help beginners.

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.