文章詳情頁(yè)
ASP新手必備的基礎(chǔ)知識(shí)
瀏覽:413日期:2022-06-05 13:03:37
我們都知道,ASP是Active Server Page的縮寫,意為“動(dòng)態(tài)服務(wù)器頁(yè)面”。ASP是微軟公司開發(fā)的代替CGI腳本程序的一種應(yīng)用,它可以與數(shù)據(jù)庫(kù)和其它程序進(jìn)行交互,是一種簡(jiǎn)單、方便的編程工具。下面介紹一些基本知識(shí),供大家參考。
一、數(shù)據(jù)庫(kù)連接
以下為引用的內(nèi)容:
<%
set conn=server.createobject("adodb.connection")
conn.open "driver={microsoft access driver (*.mdb)};dbq="&server.mappath("數(shù)據(jù)庫(kù)名")
%>
二、打開數(shù)據(jù)庫(kù)
以下為引用的內(nèi)容:
exec="select * from 數(shù)據(jù)庫(kù)表"
set rs=server.createobject("adodb.recordset")
rs.open exec,conn,1,1
參數(shù)1,1為讀取
讀取內(nèi)容格式:<%=rs("字段")%>
三、添加記錄處理程序
以下為引用的內(nèi)容:
<%
set conn=server.createobject("adodb.connection")
conn.open "driver={microsoft access driver (*.mdb)};dbq="&server.mappath("數(shù)據(jù)庫(kù)名")
name=request.form("字段") name,tel,message為提交表單所設(shè)置的字段值
tel=request.form("字段")
message=request.form("字段")
exec="insert into 表名(字段)values(""+字段+"")" 多個(gè)用逗號(hào)隔開
conn.execute exec 使用execute提交
conn.close
set conn=nothing
%>
四、搜索處理程序
以下為引用的內(nèi)容:
<%
name=request.form("字段") name,tel為提交表單所設(shè)置的字段值
tel=request.form("字段")
set conn=server.createobject("adodb.connection")
conn.open "driver={microsoft access driver (*.mdb)};dbq="&server.mappath("數(shù)據(jù)庫(kù)名")
exec="select * from 表 where name=""+字段+"" and tel="+字段
set rs=server.createobject("adodb.recordset")
rs.open exec,conn,1,1
%>
"頁(yè)面搜索到的內(nèi)容導(dǎo)出來
<%
do while not rs.eof
%><tr>
<td><%=rs("name")%></td>
<td><%=rs("tel")%></td>
<td><%=rs("time")%></td>
</tr>
<%
rs.movenext
loop
%>
五、刪除記錄處理程序
以下為引用的內(nèi)容:
<%
set conn=server.createobject("adodb.connection")
conn.open "driver={microsoft access driver (*.mdb)};dbq="&server.mappath("數(shù)據(jù)庫(kù)名")
exec="delete * from 表名 where 編號(hào)="&request.form("id")
conn.execute exec
%>
六、修改記錄處理程序
以下為引用的內(nèi)容:
<%
set conn=server.createobject("adodb.connection")
conn.open "driver={microsoft access driver (*.mdb)};dbq="&server.mappath("數(shù)據(jù)庫(kù)名")
exec="select * from 表名 where 編號(hào)="&request.form("id")
set rs=server.createobject("adodb.recordset")
rs.open exec,conn,1,3 "1,3為修改意思
rs("name")=request.form("字段") "name,tel,message為提交表單所設(shè)置的字段值
rs("tel")=request.form("字段")
rs("message")=request.form("字段")
rs.update
rs.close
set rs=nothing
conn.close
set conn=nothing
%>
修改記錄執(zhí)行程序:輸入ID號(hào)頁(yè)面>>>導(dǎo)出相對(duì)應(yīng)ID數(shù)據(jù)>>>>>>直接修改的處理程序
七、后臺(tái)登陸處理程序例子
以下為引用的內(nèi)容:
<%
dim name,password
name=request.form("name")
password=request.form("password")
dim exec,conn,rs
exec="select *from 表名 where(name=""&字段&"" and password=""&字段&"")"
set conn=server.createobject("adodb.connection")
conn.open "driver={microsoft access driver (*.mdb)};dbq="&server.mappath("數(shù)據(jù)庫(kù)名")
set rs=server.createobject("adodb.recordset")
rs.open exec,conn
if not rs.eof then
rs.Close
conn.Close
session("checked")="yes"
session("check")="right"
response.Redirect "index.asp"
else
session("checked")="no"
session("check")="wrong"
response.Redirect "login.asp"
end if
%>
每個(gè)后臺(tái)頁(yè)面加上:
<%if not session("checked")="yes" then "session里面定義一個(gè)checked字符串變量
response.Redirect "login.asp"
else
%>
希望以上對(duì)于ASP基礎(chǔ)知識(shí)的介紹,能給初學(xué)者帶來一定的幫助。
標(biāo)簽:
ASP
相關(guān)文章:
1. asp.net core項(xiàng)目授權(quán)流程詳解2. ASP.NET MVC使用異步Action的方法3. ASP腳本組件實(shí)現(xiàn)服務(wù)器重啟4. asp中response.write("中文")或者js中文亂碼問題5. AspNetCore&MassTransit Courier實(shí)現(xiàn)分布式事務(wù)的詳細(xì)過程6. ASP中if語句、select 、while循環(huán)的使用方法7. 理解ASP.NET Core 配置系統(tǒng)8. asp.net core 認(rèn)證和授權(quán)實(shí)例詳解9. 關(guān)于Jenkins + Docker + ASP.NET Core自動(dòng)化部署的問題(避免踩坑)10. asp.net core應(yīng)用docke部署到centos7的全過程
排行榜

網(wǎng)公網(wǎng)安備