Tutorials | Getting Started Tutorials | Getting Started
<%
Statement
......
%>
<2> Define Variable Dim statement
<%
Dim a,b
a=10
b= "ok!"
%>
Note: The defined variable can be a numeric type, or it can be a character or other type of
<3> Simple Control Process statement
1. If Condition 1 Then
Statement 1
ElseIf Condition 2 Then
Statement 2
Else
Statement 3
endif
2.while conditions
Statement
Wend
3.for count=1 to n step m
Statement 1
Exit For
Statement 2
Next
Two. asp Database Simple * Tutorial
<1>. Database connection (used to separate the 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 the User.mdb database in the bbs\db1\ directory)
<2> displaying database records
Principle: Display the record one by one in the database to the client browser, read out each record in the database in turn
If it's from beginning to end: Use loops and determine whether the pointer is used: not rs.eof
If it's from the end of the head: loop and determine if the pointer is to start using: Not Rs.bof
<!--#include file=conn.asp-->
(Contains conn.asp to open the User.mdb database in the bbs\db1\ directory)
<%
Set Rs=server. CreateObject ("Adodb.recordset") (Create a Recordset object)
Sqlstr= "SELECT * from Message"----> (the message is a data table in the database that you
The data table that the data to display is stored in
Rs.Open sqlstr,conn,1,3----> (indicates how the database is opened)
Rs.movefirst----> (move pointer to first record)
While not rs.eof----> (judging whether the pointer is to the end)
Response.Write (RS ("name"))----> (Display the Name field in the data table message)
Rs.movenext----> (move pointer to next record)
Wend----> (end of Loop)
------------------------------------------------------
Rs.close
Conn.close These sentences are used to close the database
Set rs=nothing
Set conn=nothing
-------------------------------------------------------
%>
Where the response object is the information that the server sends to the client browser
<3> Increase database records
Add database records to rs.addnew,rs.update two functions
<!--#include file=conn.asp-->
(Contains conn.asp to open the User.mdb database in the bbs\db1\ directory)
<%
Set Rs=server. CreateObject ("Adodb.recordset") (Create a Recordset object)
Sqlstr= "SELECT * from Message"----> (the message is a data table in the database that you
The data table that the data to display is stored in
Rs.Open sqlstr,conn,1,3----> (indicates how the database is opened)
Rs.addnew Add a new record
RS ("name") = "XX" passes the value of XX to the Name field
Rs.update Refresh the database
------------------------------------------------------
Rs.close
Conn.close These sentences are used to close the database
Set rs=nothing
Set conn=nothing
-------------------------------------------------------
%>
<4> Delete a record
Deleting database records is mainly used to rs.delete,rs.update
<!--#include file=conn.asp--> (contains conn.asp to open bbs\db1\ directory User.mdb
Database
<%
Dim name
Name= "XX"
Set Rs=server. CreateObject ("Adodb.recordset") (Create a Recordset object)
Sqlstr= "SELECT * from Message"----> (the message is a data table in the database that you
The data table that the data to display is stored in
Rs.Open sqlstr,conn,1,3----> (indicates how the database is opened)
-------------------------------------------------------
While not rs.eof
If Rs. ("name") =name Then
Rs.delete
Rs.update
Query whether the value of the Name field in the datasheet equals the value "XX" of the variable name, and if it does, delete
else or continue the query until the pointer is to the end
Rs.movenext
EMD IF
Wend
------------------------------------------------------
------------------------------------------------------
Rs.close
Conn.close These sentences are used to close the database
Set rs=nothing
Set conn=nothing
-------------------------------------------------------
%>
<5> queries about the database
(a) The query field is character type
<%
Dim user,pass,qq,mail,message
User=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" then (detect whether the user value and pass value
Blank, can detect spaces)
Response.Write ("Registration information cannot be blank")
Else
Set Rs=server