ASP connection database an hour tutorial

xiaoxiao2021-03-05  30

<% Statement ...%> <2> Define Variable DIM statement <% DIM A, BA = 10B = "OK!"%> Note: The defined variable can be a numeric value, or a character or other type of <3> Simple Control Process Statement 1. IF Condition 1 THEN State 1ELSEIF Condition 2 THEN State 2ELSE Statement 3ENDIF2.WHILE Condition Statement Wend3.for Count = 1 To N Step M Statement 1Exit for Statement 2Next Er .asp Database Simple Operation 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 USER.MDB database under BBS / DB1 / directory) <2> Display Database Recording Principle: Display the record in the database to the customer Each browser, sequentially reads each record in the database, if it is from the end to the end: cycle and judgment the pointer to the end: NOT RS.EOF If it is from the end to the header: use the loop and judge whether the pointer is started using: NOT Rs.bof (contains conn.asp User.mdb databases under BBS / DB1 / directory) <% set = server.createObject ("AdoDb.Recordset ") (Establishing a Recordset object) sqlstr =" select * from message "----> (Message is a data table in the database, that is, the data stored in the data you want to display) RS.Open SQLSTR, CONN, 1 , 3 ----> (indicating how to open the database) rs.movefirst ----> (will move the needle to the first record) while not rs.eof ----> (Judge whether the pointer is at the end) Response .write ("name") ----> (Show Name field in data table Message) rs.movenext ----> (move the pointer to the next record) Wend ----> (cycle end)------------------------------------------------ ------ rs.clos Econn.close This sentence is used to close the database SET RS = NothingSet conn = Nothing -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -----------------------%> where the response object is the server sent to the client browser <3> Add Database Record to add Database record to RS .addnew, rs.update two functions (including conn.asp User.mdb database) <% 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 ----> (indicating how to open the database) RS.AddNew adds a record RS ("Name") =

"XX" passes the value of XX to the Name field rs.Update refreshes the database ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ -------------------- r.closeconn.close This is used to close the database set = NothingSet conn = Nothing ---------- ---------------------------------------------%> <4> Delete a record delete database record mainly uses rs.delete, rs.Update (Message is a data table in the database, ie The data you want to display the data stored by rs.open sqlstr, conn, 1, 3 ----> (indicating how to open the database) ----------------- -------------------------------------- While NOT RS.EOFIF RS. ("Name") = Name Thenrs.deleters.Update Query the value of the Name field in the data table is equal to the value "XX" of the variable Name, if the execution is deleted, else does otherwise continue query until the pointer is Rs.MovenexTemd ifwend ---- -------------------------------------------------- -------------------------------------------------- ---- rs.closeconn.close This is used to close the database set = nothingset conn = Nothing -------------------------- -----------------------------%> <5> About the database's query (a) Query field is a character type <% DIM User , Pass, QQ, Mail, Messageuser = Request .Form ("user") 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" "Detects the user value and the pass value is empty, can detect the space) Response.write (" Registration information cannot be empty ") Elseset RS = Server.createObject (" AdoDb.Recordset ") SQLSTR =" SELECT * from user where user = "& user" (query User field in the user data table where the user field is characterized) RS.Open SQLSTR, CONN, 1, 3IF RS.EOF THENRS.ADDNEWRS ("User") = UserRS ("pass") =

Passrs ("QQ") = QQRS ("Mail") = mailrs ("Message") = message.Updaters.closeconn.closset RS = NothingSet conn = NothingResponse.write ("Register success") end if rs.closeconn.closeset RS = NothingSet conn = NothingResponse.write ("Registered Retriever")%> (b) Query field is digital <% DIM NUMNUM = Request.form ("NUM") set = server.createObject ("AdoDb.Recordset") SQLSTR = "Select * from message where id =" & num (Query if the value of the ID field in the Message data table is equal to NUM, where ID is digital) RS.Open SQLSTR, CONN, 1, 3IF NOT RS.EOF TENRS.DELETERS .updaters.closeconn.closeset rs = NothingSet conn = NothingResponse.write ("Delete Success") end ifrs.closeconn.closset RS = NothingSet conn = NothingResponse.write ("Delete Fail")%> <6> Several Simple ASP Object of Objects Response Object: The server side sends the information object to the client, including direct sending information to the browser, reordering the URL, or sets the cookie value REQUEST object: The client is proposed to the server Session object: as a global variable, Effective Server objects throughout the site: Provides access (a) response objects for methods and properties on the server, such as: <% Resposne.Write ("Hello, Welcome To ASP!")%> In the client browser I will see Hello, Welcome To ASP! This paragraph <% response.redirect ("www.sohu.com")%> If this paragraph is executed, the browser will automatically connect to the "Sohu" URL for the response object. There are still many usages, you can study the general usage of the Request object, such as the client proposed by the client is the column passed through the Request object, such as: you are filled out in the application mailbox Information is to pass the information you fill in to the server through this object. Entering server database

转载请注明原文地址:https://www.9cbs.com/read-34323.html

New Post(0)