ASP's Introduction to ASP Learning

Source: Internet
Author: User
Tags mdb database

First, the grammar

<1> 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

End If

2.while conditions

Statement

Wend

3.for count=1 to n step m

Statement 1

Exit For

Statement 2

Next

Two. asp database simple Operation 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--> (包含conn.asp用来打开bbs\db1\目录下的user.mdb数据库)
<%
set rs=server.CreateObject("adodb.recordset") (建立recordset对象)
sqlstr="select * from message" ---->(message为数据库中的一个数据表,即你要显示的数据所存放的数据表)
rs.open sqlstr,conn,1,3 ---->(表示打开数据库的方式)
rs.movefirst ---->(将指针移到第一条记录)
while not rs.eof ---->(判断指针是否到末尾)
response.write(rs("name")) ---->(显示数据表message中的name字段)
rs.movenext ---->(将指针移动到下一条记录)
wend ---->(循环结束)
rs.close
conn.close 这几句是用来关闭数据库
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--> (包含conn.asp用来打开bbs\db1\目录下的user.mdb数据库)
<%
set rs=server.CreateObject("adodb.recordset") (建立recordset对象)
sqlstr="select * from message" ---->(message为数据库中的一个数据表,即你要显示的数据所存放的数据表)
rs.open sqlstr,conn,1,3 ---->(表示打开数据库的方式)
rs.addnew 新增加一条记录
rs("name")="xx" 将xx的值传给name字段
rs.update 刷新数据库
rs.close
conn.close 这几句是用来关闭数据库
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--> (包含conn.asp用来打开bbs\db1\目录下的user.mdb数据库)
<%
dim name
name="xx"
set rs=server.CreateObject("adodb.recordset") (建立recordset对象)
sqlstr="select * from message" ---->(message为数据库中的一个数据表,即你要显示的数据所存放的数据表)
rs.open sqlstr,conn,1,3 ---->(表示打开数据库的方式)
while not rs.eof
if rs.("name")=name then
rs.delete
rs.update 查询数据表中的name字段的值是否等于变量name的值"xx",如果符合就执行删除,
else 否则继续查询,直到指针到末尾为止
rs.movenext
emd if
wend
rs.close
conn.close 这几句是用来关闭数据库
set rs=nothing
set conn=nothing
%>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.