相關(guān)資訊
本類常用軟件
-
福建農(nóng)村信用社手機(jī)銀行客戶端下載下載量:584204
-
Windows優(yōu)化大師下載量:416896
-
90美女秀(視頻聊天軟件)下載量:366961
-
廣西農(nóng)村信用社手機(jī)銀行客戶端下載下載量:365699
-
快播手機(jī)版下載量:325855
每日一囧
想學(xué)ASP的朋友們一定要看下面的文章了,教你在一個(gè)小時(shí)內(nèi)解決掉ASP,希望能夠幫助到大家。
一、語法
<1>語句
<%...........%>
<2>定義變量dim語句
<%
dim a,b
a=10
b=”ok!”
%>
注意:定義的變量可以是數(shù)值型,也可以是字符或者其他類型的
<3>簡單的控制流程語句
1. if 條件1 then
語句1
elseif 條件2 then
語句2
else
語句3
end if
2.while 條件
語句
wend
3.for count=1 to n step m
語句1
exit for
語句2
next
二.asp數(shù)據(jù)庫簡單*作教程
<1>.數(shù)據(jù)庫連接(用來單獨(dú)編制連接文件conn.asp)
<%
set conn = server.createobject(adodb.connection)
conn.open driver={microsoft access driver (*.mdb)}; dbq= & server.mappath(\bbs\db1\user.mdb)
%>
(用來連接bbs\db1\目錄下的user.mdb數(shù)據(jù)庫)
<2>顯示數(shù)據(jù)庫記錄
原理:將數(shù)據(jù)庫中的記錄一一顯示到客戶端瀏覽器,依次讀出數(shù)據(jù)庫中的每一條記錄
如果是從頭到尾:用循環(huán)并判斷指針是否到末 使用: not rs.eof
如果是從尾到頭:用循環(huán)并判斷指針是否到開始 使用:not rs.bof
<!--#include file=conn.asp--> (包含conn.asp用來打開bbs\db1\目錄下的user.mdb數(shù)據(jù)庫)
<%
set rs=server.createobject(adodb.recordset) (建立recordset對(duì)象)
sqlstr=select * from message ---->(message為數(shù)據(jù)庫中的一個(gè)數(shù)據(jù)表,即你要顯示的數(shù)據(jù)所存放的數(shù)據(jù)表)
rs.open sqlstr,conn,1,3 ---->(表示打開數(shù)據(jù)庫的方式)
rs.movefirst ---->(將指針移到第一條記錄)
while not rs.eof ---->(判斷指針是否到末尾)
response.write(rs(name)) ---->(顯示數(shù)據(jù)表message中的name字段)
rs.movenext ---->(將指針移動(dòng)到下一條記錄)
wend ---->(循環(huán)結(jié)束)
rs.close
conn.close 這幾句是用來關(guān)閉數(shù)據(jù)庫
set rs=nothing
set conn=nothing
%>
其中response對(duì)象是<a href='http://school.enet.com.cn/eschool/includes/zhuanti/shuyu/info/1/02/1684.shtml' target='_blank' class='article'>服務(wù)器</a>向客戶端瀏覽器發(fā)送的信息
<3>增加數(shù)據(jù)庫記錄
增加數(shù)據(jù)庫記錄用到rs.addnew,rs.update兩個(gè)函數(shù)
<!--#include file=conn.asp--> (包含conn.asp用來打開bbs\db1\目錄下的user.mdb數(shù)據(jù)庫)
<%
set rs=server.createobject(adodb.recordset) (建立recordset對(duì)象)
sqlstr=select * from message ---->(message為數(shù)據(jù)庫中的一個(gè)數(shù)據(jù)表,即你要顯示的數(shù)據(jù)所存放的數(shù)據(jù)表)
rs.open sqlstr,conn,1,3 ---->(表示打開數(shù)據(jù)庫的方式)
rs.addnew 新增加一條記錄
rs(name)=xx 將xx的值傳給name字段
rs.update 刷新數(shù)據(jù)庫
rs.close
conn.close 這幾句是用來關(guān)閉數(shù)據(jù)庫
set rs=nothing
set conn=nothing
%>
<4>刪除一條記錄
刪除數(shù)據(jù)庫記錄主要用到rs.delete,rs.update
<!--#include file=conn.asp--> (包含conn.asp用來打開bbs\db1\目錄下的user.mdb數(shù)據(jù)庫)
<%
dim name
name=xx
set rs=server.createobject(adodb.recordset) (建立recordset對(duì)象)
sqlstr=select * from message ---->(message為數(shù)據(jù)庫中的一個(gè)數(shù)據(jù)表,即你要顯示的數(shù)據(jù)所存放的數(shù)據(jù)表)
rs.open sqlstr,conn,1,3 ---->(表示打開數(shù)據(jù)庫的方式)
while not rs.eof
if rs.(name)=name then
rs.delete
rs.update 查詢數(shù)據(jù)表中的name字段的值是否等于變量name的值xx,如果符合就執(zhí)行刪除,
else 否則繼續(xù)查詢,直到指針到末尾為止
rs.movenext
emd if
wend
rs.close
conn.close 這幾句是用來關(guān)閉數(shù)據(jù)庫
set rs=nothing
set conn=nothing
%>
<5>關(guān)于數(shù)據(jù)庫的查詢
(a) 查詢字段為字符型
<%
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 (檢測(cè)user值和pass值是否為空,可以檢測(cè)到空格)
response.write(注冊(cè)信息不能為空)
else
set rs=server.createobject(adodb.recordset)
sqlstr=select * from user where user='&user&' (查詢user數(shù)據(jù)表中的user字段其中user字段為字符型)
rs.open sqlstr,conn,1,3
if rs.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(注冊(cè)成功)
end if
rs.close
conn.close
set rs=nothing
set conn=nothing
response.write(注冊(cè)重名)
%>
(b)查詢字段為數(shù)字型
<%
dim num
num=request.form(num)
set rs=server.createobject(adodb.recordset)
sqlstr=select * from message where id=&num (查詢message數(shù)據(jù)表中id字段的值是否與num相等,其中id為數(shù)字型)
rs.open sqlstr,conn,1,3
if not rs.eof then
rs.delete
rs.update
rs.close
conn.close
set rs=nothing
set conn=nothing
response.write(刪除成功)
end if
rs.close
conn.close
set rs=nothing
set conn=nothing
response.write(刪除失敗)
%>
<6>幾個(gè)簡單的asp對(duì)象的講解
response對(duì)象:服務(wù)器端向客戶端發(fā)送的信息對(duì)象,包括直接發(fā)送信息給瀏覽器,重新定向url,或設(shè)置cookie值
request對(duì)象:客戶端向服務(wù)器提出的請(qǐng)求
session對(duì)象:作為一個(gè)全局變量,在整個(gè)站點(diǎn)都生效
server對(duì)象:提供對(duì)服務(wù)器上方法和屬性的訪問
(a) response對(duì)象的一般使用方法
比如:
<%
resposne.write(hello, welcome to asp!)
%>
在客戶端瀏覽器就會(huì)看到 hello, welcome to asp! 這一段文字
<%
response.redirect(www.sohu.com)
%>
如果執(zhí)行這一段,則瀏覽器就會(huì)自動(dòng)連接到 “搜狐” 的網(wǎng)址
關(guān)于response對(duì)象的用法還有很多,大家可以研究研究
request對(duì)象的一般使用方法
比如客戶端向服務(wù)器提出的請(qǐng)求就是通過request對(duì)象來傳遞的列如 :你在申請(qǐng)郵箱的所填寫的個(gè)人信息就是通過該對(duì)象來將你所填寫的信息傳遞給服務(wù)器的
比如:這是一段表單的代碼,這是提供給客戶填寫信息的,填寫完了按“提交”傳遞給request.asp文件處理后再存入服務(wù)器數(shù)據(jù)庫
<form name=form1 method=post action=request.asp>
<p>
<input type=text name=user>
</p>
<p>
<input type=text name=pass>
</p>
<p>
<input type=submit name=submit value=提交>
</p>
</form>
那么request.asp該如何將其中的信息讀入,在寫入數(shù)據(jù)庫,在這里就要用到
request對(duì)象了,下面我們就來分析request.asp的寫法
<%
dim name,password (定義user和password兩個(gè)變量)
name=request.form(“user”) (將表單中的user信息傳給變量name)
password=request.form(“pass”) (將表單中的pass信息傳給變量password)
%>
通過以上的幾句代碼我們就將表單中的數(shù)據(jù)讀進(jìn)來了,接下來我們要做的就是將
信息寫入數(shù)據(jù)庫了,寫入數(shù)據(jù)庫的方法上面都介紹了,這里就不一一復(fù)述了。
<1>語句
<%...........%>
<2>定義變量dim語句
<%
dim a,b
a=10
b=”ok!”
%>
注意:定義的變量可以是數(shù)值型,也可以是字符或者其他類型的
<3>簡單的控制流程語句
1. if 條件1 then
語句1
elseif 條件2 then
語句2
else
語句3
end if
2.while 條件
語句
wend
3.for count=1 to n step m
語句1
exit for
語句2
next
二.asp數(shù)據(jù)庫簡單*作教程
<1>.數(shù)據(jù)庫連接(用來單獨(dú)編制連接文件conn.asp)
<%
set conn = server.createobject(adodb.connection)
conn.open driver={microsoft access driver (*.mdb)}; dbq= & server.mappath(\bbs\db1\user.mdb)
%>
(用來連接bbs\db1\目錄下的user.mdb數(shù)據(jù)庫)
<2>顯示數(shù)據(jù)庫記錄
原理:將數(shù)據(jù)庫中的記錄一一顯示到客戶端瀏覽器,依次讀出數(shù)據(jù)庫中的每一條記錄
如果是從頭到尾:用循環(huán)并判斷指針是否到末 使用: not rs.eof
如果是從尾到頭:用循環(huán)并判斷指針是否到開始 使用:not rs.bof
<!--#include file=conn.asp--> (包含conn.asp用來打開bbs\db1\目錄下的user.mdb數(shù)據(jù)庫)
<%
set rs=server.createobject(adodb.recordset) (建立recordset對(duì)象)
sqlstr=select * from message ---->(message為數(shù)據(jù)庫中的一個(gè)數(shù)據(jù)表,即你要顯示的數(shù)據(jù)所存放的數(shù)據(jù)表)
rs.open sqlstr,conn,1,3 ---->(表示打開數(shù)據(jù)庫的方式)
rs.movefirst ---->(將指針移到第一條記錄)
while not rs.eof ---->(判斷指針是否到末尾)
response.write(rs(name)) ---->(顯示數(shù)據(jù)表message中的name字段)
rs.movenext ---->(將指針移動(dòng)到下一條記錄)
wend ---->(循環(huán)結(jié)束)
rs.close
conn.close 這幾句是用來關(guān)閉數(shù)據(jù)庫
set rs=nothing
set conn=nothing
%>
其中response對(duì)象是<a href='http://school.enet.com.cn/eschool/includes/zhuanti/shuyu/info/1/02/1684.shtml' target='_blank' class='article'>服務(wù)器</a>向客戶端瀏覽器發(fā)送的信息
<3>增加數(shù)據(jù)庫記錄
增加數(shù)據(jù)庫記錄用到rs.addnew,rs.update兩個(gè)函數(shù)
<!--#include file=conn.asp--> (包含conn.asp用來打開bbs\db1\目錄下的user.mdb數(shù)據(jù)庫)
<%
set rs=server.createobject(adodb.recordset) (建立recordset對(duì)象)
sqlstr=select * from message ---->(message為數(shù)據(jù)庫中的一個(gè)數(shù)據(jù)表,即你要顯示的數(shù)據(jù)所存放的數(shù)據(jù)表)
rs.open sqlstr,conn,1,3 ---->(表示打開數(shù)據(jù)庫的方式)
rs.addnew 新增加一條記錄
rs(name)=xx 將xx的值傳給name字段
rs.update 刷新數(shù)據(jù)庫
rs.close
conn.close 這幾句是用來關(guān)閉數(shù)據(jù)庫
set rs=nothing
set conn=nothing
%>
<4>刪除一條記錄
刪除數(shù)據(jù)庫記錄主要用到rs.delete,rs.update
<!--#include file=conn.asp--> (包含conn.asp用來打開bbs\db1\目錄下的user.mdb數(shù)據(jù)庫)
<%
dim name
name=xx
set rs=server.createobject(adodb.recordset) (建立recordset對(duì)象)
sqlstr=select * from message ---->(message為數(shù)據(jù)庫中的一個(gè)數(shù)據(jù)表,即你要顯示的數(shù)據(jù)所存放的數(shù)據(jù)表)
rs.open sqlstr,conn,1,3 ---->(表示打開數(shù)據(jù)庫的方式)
while not rs.eof
if rs.(name)=name then
rs.delete
rs.update 查詢數(shù)據(jù)表中的name字段的值是否等于變量name的值xx,如果符合就執(zhí)行刪除,
else 否則繼續(xù)查詢,直到指針到末尾為止
rs.movenext
emd if
wend
rs.close
conn.close 這幾句是用來關(guān)閉數(shù)據(jù)庫
set rs=nothing
set conn=nothing
%>
<5>關(guān)于數(shù)據(jù)庫的查詢
(a) 查詢字段為字符型
<%
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 (檢測(cè)user值和pass值是否為空,可以檢測(cè)到空格)
response.write(注冊(cè)信息不能為空)
else
set rs=server.createobject(adodb.recordset)
sqlstr=select * from user where user='&user&' (查詢user數(shù)據(jù)表中的user字段其中user字段為字符型)
rs.open sqlstr,conn,1,3
if rs.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(注冊(cè)成功)
end if
rs.close
conn.close
set rs=nothing
set conn=nothing
response.write(注冊(cè)重名)
%>
(b)查詢字段為數(shù)字型
<%
dim num
num=request.form(num)
set rs=server.createobject(adodb.recordset)
sqlstr=select * from message where id=&num (查詢message數(shù)據(jù)表中id字段的值是否與num相等,其中id為數(shù)字型)
rs.open sqlstr,conn,1,3
if not rs.eof then
rs.delete
rs.update
rs.close
conn.close
set rs=nothing
set conn=nothing
response.write(刪除成功)
end if
rs.close
conn.close
set rs=nothing
set conn=nothing
response.write(刪除失敗)
%>
<6>幾個(gè)簡單的asp對(duì)象的講解
response對(duì)象:服務(wù)器端向客戶端發(fā)送的信息對(duì)象,包括直接發(fā)送信息給瀏覽器,重新定向url,或設(shè)置cookie值
request對(duì)象:客戶端向服務(wù)器提出的請(qǐng)求
session對(duì)象:作為一個(gè)全局變量,在整個(gè)站點(diǎn)都生效
server對(duì)象:提供對(duì)服務(wù)器上方法和屬性的訪問
(a) response對(duì)象的一般使用方法
比如:
<%
resposne.write(hello, welcome to asp!)
%>
在客戶端瀏覽器就會(huì)看到 hello, welcome to asp! 這一段文字
<%
response.redirect(www.sohu.com)
%>
如果執(zhí)行這一段,則瀏覽器就會(huì)自動(dòng)連接到 “搜狐” 的網(wǎng)址
關(guān)于response對(duì)象的用法還有很多,大家可以研究研究
request對(duì)象的一般使用方法
比如客戶端向服務(wù)器提出的請(qǐng)求就是通過request對(duì)象來傳遞的列如 :你在申請(qǐng)郵箱的所填寫的個(gè)人信息就是通過該對(duì)象來將你所填寫的信息傳遞給服務(wù)器的
比如:這是一段表單的代碼,這是提供給客戶填寫信息的,填寫完了按“提交”傳遞給request.asp文件處理后再存入服務(wù)器數(shù)據(jù)庫
<form name=form1 method=post action=request.asp>
<p>
<input type=text name=user>
</p>
<p>
<input type=text name=pass>
</p>
<p>
<input type=submit name=submit value=提交>
</p>
</form>
那么request.asp該如何將其中的信息讀入,在寫入數(shù)據(jù)庫,在這里就要用到
request對(duì)象了,下面我們就來分析request.asp的寫法
<%
dim name,password (定義user和password兩個(gè)變量)
name=request.form(“user”) (將表單中的user信息傳給變量name)
password=request.form(“pass”) (將表單中的pass信息傳給變量password)
%>
通過以上的幾句代碼我們就將表單中的數(shù)據(jù)讀進(jìn)來了,接下來我們要做的就是將
信息寫入數(shù)據(jù)庫了,寫入數(shù)據(jù)庫的方法上面都介紹了,這里就不一一復(fù)述了。
熱門評(píng)論
最新評(píng)論