1 hour ASP started, very simple.
<% Statement ...%> <2> Define Variable DIM statement <% DIM A, B A = 10 B = "OK!"%> Note: Defined change beams are numerical, or other types or other types <3> Simple Control Process Statement 1. IF Condition 1 THEN State 1ELSEIF Condition 2 THEN SOSE 2ELSE Statement 3Endif2.While Condition Statement Wend3.for Count = 1 To N Step M Statement 1 EXIT for Statement 2Next II.ASP Database Simple * Tutorial <1>. Database connection (used to prepare connection file conn.asp <% set conn = server.createObject ("adoDb.connection" conn.open "driver = {Microsoft Access Driver (* .mdb)} DBQ = "& Server.mappath (" / bbs / db1 / user.mdb)%> (used to connect to the USER.MDB database under the BBS / DB1 / directory) <2> Display Database Recording Principle: Put the database Record one by one to the client browser, sequentially read out the record in the database, if it is from the end to the end: use the loop and determine whether the pointer is used to use: NOT RS.EOF If it is from the end to the head: use a loop and judge the pointer Whether to start using: NOT RS.BOF (containing conn.asp to open the USER.MDB database under the BBS / DB1 / directory) <% SET RS = Server. CreateObject ("AdoDb.Recordset") (established RECORDSET object) SQLSTR = "Select * from message" ----> (Message is a data table in the database, that is, the data stored by the data you want to display) RS. Open SQLSTR, CONN, 1, 3 ----> (means the way to open the database) rs.movefirst ----> (Move the needle to the first record) While Not Rs.eof ----> (Judge whether the pointer is at the end) Response.write (RS ("Name")) ----> (Display Name field in Dataset Message) rs.MoveNext ----> (Move pointer) To the next record) Wend ----> (End of the loop) ----------------------------------- ------------------- rs.close conn.close This is used to close the database set = Nothing set conn = Nothing --------- ---------------------------------------------%> where Response Object is the information sent to the client browser <3>
Add Database Record Add Database Record to use rs.addnew, rs.update two functions (including conn.asp User.mdb under BBS / DB1 / directory Database) <% SET RS = Server.createObject ("AdoDb.Recordset") (established RECORDSET Object) SQLSTR = "Select * from message" ----> (Message is a data table in the database, you want to display Data stored in data) RS.Open SQLSTR, CONN, 1, 3 ----> (indicating that the way to open the database) rs.addNew adds a record RS ("Name") = "xx" to set the value of XX Pass to the Name field rs.Update refreshed database --------------------------------------- ------------- rs.close conn.close This sentence is used to close the database set = Nothing set conn = Nothing --------------- ----------------------------------------%> <4> Delete a record delete database The record mainly uses rs.delete, rs.Update (including conn.asp User.mdb database User.mdb database under BBS / DB1 / directory) <% DIM Name Name = "xx" set = server.createObject ("AdoDb.Recordset") (establish a Recordset object) SQLSTR = "Select * from message" ----> (Message is a data sheet in the database, that is, the data stored by the data you want to display) rs.open sqlstr, conn, 1, 3 ----> (Means the way to open the database) ----------------------------------------- ------------ While NOT RS.EOF IF RS. ("Name") = Name THEN RS.DELETE RS.UPDATE Querying the value of the Name field in the data table is equal to the value of the variable Name XX ", if you meet, execute it,
Else Otherwise, continues to query until the pointer is Rs.Movenext EMD IF WEND ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ -------------------------------------------------- ------------------------ rs.close conn.close This sentence is used to close the database set = Nothing set conn = Nothing ---- -------------------------------------------------- -%> <5> About database query (a) Query field is a characteristic <% DIM User, Pass, QQ, Mail, Message User = Request.form ("" ") PASS = Request.form (" PASS ") QQ = Request.form ("QQ") Mail = Request.form ("Mail") Message = Request.form ("Message) IF Trim (user) &" x "=" x "or trim (pass) &" X "=" x "then (detecting whether the user value and the pass value are empty, can detect the space) Response.write (" Registration Information cannot be empty ") Else Set RS = Server.createObject (" AdoDb.Recordset ") SQLSTR = "SELECT * from user where user = '" & user "(query User field in the user data table) RS.Open SQLSTR, CONN, 1, 3 IF RS.EOF THEN RS.ADDNEW RS ("User") = User RS ("pass") = pass RS ("QQ") = QQ RS ("Mail") = Mail Rs ("Message") = message = message = nothing set conn = Nothing response.write ("Register success") End if = nothing response.write ("Registered Heavy Num"%> (b) Query field is digital <% DIM NUM NUM = Request.form ("NUM") SET RS = Server.createObject ("
AdoDb.recordset ") SQLSTR =" Select * from message where id = "& num (Query the value of the ID field in the Message Data table is equal to NUM, where ID is digital) RS.Open SQLSTR, CONN, 1, 3 if Not NOT Rs.EOF THEN RS.DELETE RS.UPDATE RS.Close Conn.close Set Rs = Nothing Set Conn = Nothing Response.write ("Delete Success") end if = nothing set conn = Nothing response .write ("Delete Failed")%> <6> Drave Trolls of Simple ASP objects: The information object sent to the client side, including direct sending information to the browser, reordering the URL, or set the cookie value REQUEST object: The client requests Session object to the server: As a global variable, it takes effect throughout the site: providing access to the client and attribute access (a) Response object, for example: <% resposposne. Write ("Hello, Welcome To ASP!")%> When the client browser will see Hello, Welcome To ASP! This paragraph <% response.redirect ("www.sohu.com")%> If this is executed In a paragraph, the browser will automatically connect to the URL of "Sohu" about the use of the response object. You can study the general use of the REQUEST object, such as the client proposed by the client is the column passed through the Request object. Such as: The personal information you fill in the mailbox is to pass the information to the server to the server through this object, such as: This is the code for a form, this is to fill in the information to the customer, fill in the completion of " Submit "Delivery to the Request.asp file Processing and then store the server database