ASP Getting Started Tutorial 1 Hours ASP Getting Started, very simple

xiaoxiao2021-03-06  42

<%

Statement

......

%>

<2> Define Variables DIM statement

<%

Dim a, b

A = 10

B = "ok!"

%>

Note: The defined variables can be numeric types, or other types of characters or other types.

<3> Simple Control Process Statement

IF condition 1 THEN

Statement 1

Elseif Conditions 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

2. Simple * tutorial

<1>. Database connection (used to separate 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 Record

Principle: Display the record in the database to the client browser, read out each record in the database

If it is from the end to the end: use the loop and judge whether the pointer is used to use: Not r ..

If it is from the tail to the head: use the loop and judge whether the pointer is started using: NOT RS.BOF

(Including conn.asp to open USER.MDB database under BBS / DB1 / directory)

<%

SET RS = Server.createObject ("AdoDb.Recordset") (create a Recordset object)

SQLSTR = "Select * from message" ----> (Message is a data table in the database, that is, you

Data table to display data)

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 (RS ("Name")) ----> (Displays the Name field in the data table message)

rs.movenext ----> (move the pointer to the next record)

Wend ----> (End of the loop)

-------------------------------------------------- ----

Rs.close

Conn.close This sentence is used to close the database

SET RS = Nothing

Set conn = Nothing

-------------------------------------------------- -----

%>

Where the Response object is the information sent to the client browser to the client browser

<3> Added Database Record

Add database records to rs.addnew, rs.Update two functions

(Including conn.asp to open USER.MDB database under 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, you

Data table to display data)

RS.Open SQLSTR, CONN, 1, 3 ----> (indicating how to open the database)

Rs.AddNew adds a record

RS ("Name") = "xx" passes the value of the XX to the Name field

Rs.Update Refresh Database

-------------------------------------------------- ----

Rs.close

Conn.close This sentence is used to close the database

SET RS = Nothing

Set conn = Nothing

-------------------------------------------------- -----

%>

<4> Delete a record

Delete database records mainly use rs.delete, rs.Update

(contains conn.asp to open USER.MDB under BBS / DB1 / directory

database)

<%

DIM Name

Name = "xx"

SET RS = Server.createObject ("AdoDb.Recordset") (create a Recordset object)

SQLSTR = "Select * from message" ----> (Message is a data table in the database, that is, you

Data table to display data)

RS.Open SQLSTR, CONN, 1, 3 ----> (indicating how to open the database)

-------------------------------------------------- -----

While Not Rs.eof

IF RS. ("Name") = Name Then

Rs.delete

Rs.Update

Query if the value of the Name field in the data table is equal to the value "XX" of the variable Name, if it meets, execute the delete,

Otherwise, continue to query until the pointer is until the end

rs.movenext

EMD IF

Wend

-------------------------------------------------- ----

-------------------------------------------------- ----

Rs.close

Conn.close This sentence is used to close the database

SET RS = Nothing

Set conn = Nothing

-------------------------------------------------- -----

%>

<5> Query about the database

(a) 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" (detects if the USER value and the pass value are

It is empty, you can detect spaces)

Response.write ("Registration Information cannot be empty")

Else

SET RS = Server.createObject ("AdoDb.Recordset")

SQLSTR = "Select * from user where user = '" & user "(query user in the USER data table

Field where the user field is a character type)

Rs.open SQLSTR, CONN, 1, 3

IF r.eof then

rs.addnew

RS ("User" = User

RS ("pass") = pass

RS ("QQ") = QQ

RS ("mail") = MAIL

RS ("Message) = Message

Rs.Update

Rs.close

Conn.close

SET RS = Nothing

Set conn = Nothing

Response.write ("Register Success")

END IF

Rs.close

Conn.close

SET RS = Nothing

Set conn = Nothing

Response.write ("Registered Repetition")

%>

(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 ID field in the Message data table

Whether the value is equal to NUM, where ID is digital)

Rs.open SQLSTR, CONN, 1, 3

IF not r.

Rs.delete

Rs.Update

Rs.close

Conn.close

SET RS = Nothing

Set conn = Nothing

Response.write ("Delete Success")

END IF

Rs.close

Conn.close

SET RS = Nothing

Set conn = Nothing

Response.write ("Delete Fail")

%>

<6> Trist of several simple ASP objects

Response object: The server is sent to the client, including direct sending information to the browser, reordering the URL,

Or set the cookie value

Request object: Request for clients to the server

SESSION object: as a global variable, take effect throughout the site

Server object: Provide access to methods and properties on the server

(a) General usage of response objects

such as:

<%

Resposne.write ("Hello, Welcome to ASP!")

%>

Will you see Hello, Welcome to ASP! This paragraph text in the client browser

<%

Response.Redirect ("www.sohu.com")%>

If this segment is executed, the browser will automatically connect to the URL of Sohu.

There are still a lot about the usage of the response object, you can study research

General usage method for request object

For example, the client proposed to the server is passed through the Request object.

Such as: The personal information you filled in the mailbox will pass the object.

The information you fill in is passed to the server

For example: This is a form of a form, this is to fill in the information to the customer, fill in the completion

"Submit" is passed to the Request.asp file processing and then stored in the server database

So how to read the information in it, it is necessary to use it here.

Request object, let's analyze the write method of Request.asp

<%

DIM Name, Password (define two variables of user and password)

Name = Request.form ("User") (Pass the user information in the form to the variable Name)

Password = Request.form ("pass") (pass the pass information in the form to Variable Password)

%>

Through the above code, we read the data in the form, and then we have to do will

Information is written to the database

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

New Post(0)