熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

ASP程序員必備的知識

2022-06-13   來源: .NET編程 

  數據庫連接
<%
set conn=servercreateobject(adodbconnection)
connopen driver={microsoft access driver (*mdb)};dbq=&servermappath(數據庫名)
%>

  打開數據庫

  exec=select * from 數據庫表
set rs=servercreateobject(adodbrecordset)
rsopen execconn
參數為讀取
讀取內容格式<%=rs(字段)%>
添加記錄處理程序

  <%
set conn=servercreateobject(adodbconnection)
connopen driver={microsoft access driver (*mdb)};dbq=&servermappath(數據庫名)
name=requestform(字段) nametelmessage為提交表單所設置的字段值
tel=requestform(字段)
message=requestform(字段)
exec=insert into 表名(字段)values(;+字段+;) 多個用逗號隔開
connexecute exec 使用execute提交
connclose
set conn=nothing
%>

  搜索處理程序:

  <%
name=requestform(字段) nametel為提交表單所設置的字段值
tel=requestform(字段)
set conn=servercreateobject(adodbconnection)
connopen driver={microsoft access driver (*mdb)};dbq=&servermappath(數據庫名)
exec=select * from 表 where name=;+字段+; and tel=+字段
set rs=servercreateobject(adodbrecordset)
rsopen execconn
%>

  ;頁面搜索到的內容導出來

  <%
do while not rseof
%><tr>
<td><%=rs(name)%></td>
<td><%=rs(tel)%></td>
<td><%=rs(time)%></td>
</tr>
<%
rsmovenext
loop
%>

  刪除記錄處理程序:

  <%
set conn=servercreateobject(adodbconnection)
connopen driver={microsoft access driver (*mdb)};dbq=&servermappath(數據庫名)
exec=delete * from 表名 where 編號=&requestform(id)
connexecute exec
%>

  修改記錄處理程序:

  <%
set conn=servercreateobject(adodbconnection)
connopen driver={microsoft access driver (*mdb)};dbq=&servermappath(數據庫名)
exec=select * from 表名 where 編號=&requestform(id)
set rs=servercreateobject(adodbrecordset)
rsopen execconn ;為修改意思
rs(name)=requestform(字段) ;nametelmessage為提交表單所設置的字段值
rs(tel)=requestform(字段)
rs(message)=requestform(字段)
rsupdate
rsclose
set rs=nothing
connclose
set conn=nothing
%>

  
修改記錄執行程序:輸入ID號頁面>>>導出相對應ID數據>>>>>>直接修改的處理程序
後台登陸處理程序例子:

  
<%
dim namepassword
name=requestform(name)
password=requestform(password)
dim execconnrs
exec=select *from 表名 where(name=;&字段&; and password=;&字段&;)
set conn=servercreateobject(adodbconnection)
connopen driver={microsoft access driver (*mdb)};dbq=&servermappath(數據庫名)
set rs=servercreateobject(adodbrecordset)
rsopen execconn
if not rseof then
rsClose
connClose
session(checked)=yes
session(check)=right
responseRedirect indexasp
else
session(checked)=no
session(check)=wrong
responseRedirect loginasp
end if
%>

  每個後台頁面加上:

  <%if not session(checked)=yes then ;session裡面定義一個checked字符串變量
responseRedirect loginasp
else
%>


From:http://tw.wingwit.com/Article/program/net/201311/14463.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.