每個ASP程序員必備(bèi)的知(zhī)識
數據庫連接:
<%
set conn=server.createobject("adodb.connection")
conn.open "driver={microsoft access driver (*.mdb)};dbq="&server.mappath("數據庫(kù)名")
%>
打開數據庫:
exec="select * from 數據庫表"
set rs=server.createobject("adodb.recordset")
rs.open exec,conn,1,1
參數1,1為讀(dú)取
讀取內容格(gé)式:<%=rs("字段")%>
添加記錄處理程(chéng)序:
<%
set conn=server.createobject("adodb.connection")
conn.open "driver={microsoft access driver (*.mdb)};dbq="&server.mappath("數(shù)據庫名")
name=request.form("字(zì)段") name,tel,message為提(tí)交表單所設置(zhì)的字段值
tel=request.form("字段")
message=request.form("字段")
exec="insert into 表名(字(zì)段)values(';"+字段+"';)" 多個用逗號隔開
conn.execute exec 使用execute提交
conn.close
set conn=nothing
%>
搜索處(chù)理程序:
<%
name=request.form("字段(duàn)") name,tel為提交表單所設(shè)置(zhì)的字段值
tel=request.form("字段(duàn)")
set conn=server.createobject("adodb.connection")
conn.open "driver={microsoft access driver (*.mdb)};dbq="&server.mappath("數據庫名")
exec="select * from 表 where name=';"+字(zì)段+"'; and tel="+字段(duàn)
set rs=server.createobject("adodb.recordset")
rs.open exec,conn,1,1
%>
';頁麵(miàn)搜索到的內容導出來(lái)
<%
do while not rs.eof
%><tr>
<td><%=rs("name")%></td>
<td><%=rs("tel")%></td>
<td><%=rs("time")%></td>
</tr>
<%
rs.movenext
loop
%>
刪除記錄處理程序(xù):
<%
set conn=server.createobject("adodb.connection")
conn.open "driver={microsoft access driver (*.mdb)};dbq="&server.mappath("數據(jù)庫名")
exec="delete * from 表名 where 編號="&request.form("id")
conn.execute exec
%>
修改記錄處理程序:
<%
set conn=server.createobject("adodb.connection")
conn.open "driver={microsoft access driver (*.mdb)};dbq="&server.mappath("數據庫名")
exec="select * from 表名 where 編號="&request.form("id")
set rs=server.createobject("adodb.recordset")
rs.open exec,conn,1,3 ';1,3為修改(gǎi)意思
rs("name")=request.form("字段") ';name,tel,message為提交表單所設置的字段(duàn)值
rs("tel")=request.form("字段")
rs("message")=request.form("字段")
rs.update
rs.close
set rs=nothing
conn.close
set conn=nothing
%>
修改(gǎi)記(jì)錄(lù)執行程序:輸入ID號頁麵(miàn)>>>導出相對應ID數據>>>>>>直(zhí)接修改的處理程序
後台登陸處理程(chéng)序例(lì)子(zǐ):
<%
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("數據庫名")
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
%>
每個後台(tái)頁麵加(jiā)上(shàng):
<%if not session("checked")="yes" then ';session裏(lǐ)麵定義一個checked字符串(chuàn)變量
response.Redirect "login.asp"
else
%>
關鍵詞:ASP
閱讀本文後您有(yǒu)什麽感(gǎn)想? 已有 人給(gěi)出評(píng)價!
- 1
- 1
- 1
- 5
- 11
- 1