ASP Tutorial: Some necessary knowledge for every ASP programmer
Database connection:
The following is the quoted content:
<%
set conn=server.createobject(adodb.connection)
conn.open driver={microsoft access driver (*.mdb)};dbq=&server.mappath(database name)
%>
Open the database:
The following is the quoted content:
exec=select * from database table
set rs=server.createobject(adodb.recordset)
rs.open exec,conn,1,1
Parameter 1, 1 is read
Read content format: <%=rs(field)%>
Add record handler:
The following is the quoted content:
<%
set conn=server.createobject(adodb.connection)
conn.open driver={microsoft access driver (*.mdb)};dbq=&server.mappath(database name)
name=request.form (field) name, tel, message are the field values set for submitting the form
tel=request.form(field)
message=request.form(field)
exec=insert into table name (field) values ('+field+') multiples separated by commas
conn.execute exec uses execute to submit
conn.close
set conn=nothing
%>
Search handler:
The following is the quoted content:
<%
name=request.form(field) name,tel are the field values set for submitting the form
tel=request.form(field)
set conn=server.createobject(adodb.connection)
conn.open driver={microsoft access driver (*.mdb)};dbq=&server.mappath(database name)
exec=select * from table where name='+field+' and tel=+field
set rs=server.createobject(adodb.recordset)
rs.open exec,conn,1,1
%>
'Export the content searched on the page
<%
do while not rs.eof
%><tr>
<td><%=rs(name)%></td>
<td><%=rs(tel)%></td>
<td><%=rs(time)%></td>
</tr>
<%
rs.movenext
loop
%>
Delete record handler:
The following is the quoted content:
<%
set conn=server.createobject(adodb.connection)
conn.open driver={microsoft access driver (*.mdb)};dbq=&server.mappath(database name)
exec=delete * from table name where number=&request.form(id)
conn.execute exec
%>
Modify record handler:
The following is the quoted content:
<%
set conn=server.createobject(adodb.connection)
conn.open driver={microsoft access driver (*.mdb)};dbq=&server.mappath(database name)
exec=select * from table name where number=&request.form(id)
set rs=server.createobject(adodb.recordset)
rs.open exec,conn,1,3 '1,3 is to modify the meaning
rs(name)=request.form(field) 'name,tel,message are the field values set for submitting the form
rs(tel)=request.form(field)
rs(message)=request.form(field)
rs.update
rs.close
set rs=nothing
conn.close
set conn=nothing
%>
Modify record execution program: Input ID number page>>>>Export corresponding ID data>>>>>>Processor for direct modification
Background login handler example:
The following is the quoted content:
<%
dim name,password
name=request.form(name)
password=request.form(password)
dim exec,conn,rs
exec=select *from table name where(name='&field&' and password='&field&')
set conn=server.createobject(adodb.connection)
conn.open driver={microsoft access driver (*.mdb)};dbq=&server.mappath(database name)
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
%>
Add to each backend page:
<%if not session(checked)=yes then 'define a checked string variable in session
response.Redirect login.asp
else
%>