asp網(wǎng)站制作教程之程序員必備知識
2012/8/27 17:30:35 閱讀:2263
發(fā)布者:2263
數(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為讀取
讀取內容格式:<%=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
%>
';頁面搜索到的內容導出來
<%
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 "dri