<1> <% Statement ......%>
<2> Define Variable Dim statement
<%Dim a,ba=10b= "ok! "%>// NOTE: The defined variable can be numeric, or it can be a character or other type of
<3> simple control of flow statements
1
If Condition 1 Then
Statement 1
ElseIf Condition 2 Then
Statement 2
Else
Statement 3
endif
2
While condition
Statement
Wend
3
For Count=1 to n step m
Statement 1
Exit For
Statement 2
Next
Two database operations
<%Set Conn= Server.CreateObject ("ADODB. Connection ") Conn. Open"Driver={microsoft Access DRIVER (*.mdb)}; Dbq= "& Server.MapPath ("\bbs\db1\user.mdb")%>//Database Connection<!--#include file=conn.asp--><%SetRs=server. CreateObject ("Adodb.recordset")//Set up the Recordset object Sqlstr="SELECT * from Message" //(message is a data table in the database, which is the data table that you want to display the data in)Rs.Open sqlstr,conn,1,3//(indicates how the database is opened)Rs.movefirst//(move the pointer to the first record) whileNot rs.eof//(Judging if the pointer is to the end)Response.Write (RS ("Name"))//(Displays the Name field in the data table message)Rs.movenext//(move the pointer to the next record)Wend//(end of cycle)Rs.closeconn.close//These sentences are used to close the databaseSetrs= NothingSetconn= Nothing%>
adding database records
<!--#include file=conn.asp--><%SetRs=server. CreateObject ("Adodb.recordset") (build Recordset object) Sqlstr="SELECT * from Message"//(message is a data table in the database, which is the data table that you want to display the data in)Rs.Open sqlstr,conn,1,3//(indicates how the database is opened)Rs.addnew adds a new record RS ("Name")="XX"Pass the value of XX to the Name field Rs.update Refresh the database rs.closeconn.close//These sentences are used to close the databaseSetrs= NothingSetconn= Nothing%>
Delete a record
<!--#include file=conn.asp--><%Dim NameName="XX"SetRs=server. CreateObject ("Adodb.recordset") (build Recordset object) Sqlstr="SELECT * from Message"Rs.Open Sqlstr,conn,1,3 whileNot rs.eofifRs. ("Name")=name then Rs.Deleters.update//The value of the name field in the Query data table is equal to the value "XX" of the variable name, and if it is met , the deletion is performed.Elseotherwise continue the query until the pointer is to the end Rs.movenextendifWendrs.closeconn.closeSetrs= NothingSetconn= Nothing%>
1-Hour Introductory ASP