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