TA的每日心情 | 衰 2019-8-18 09:37 |
|---|
签到天数: 2 天 [LV.1]初来乍到
|
数据库连接:
& _. A; n1 Y2 q# k<%
+ M$ f7 @6 p0 ]& k n% ~- M- ^& Pset conn=server.createobject("adodb.connection")' s, U$ ^4 {, t( x: S
conn.open "driver={microsoft access driver (*.mdb)};dbq="&server.mappath("数据库名")
" |$ s* s0 R$ d$ G3 R%>
8 C% q5 H5 f+ \) N* Q9 q
' m6 q5 B9 E) W0 X5 u
; m+ E" p% u( g/ b$ S& X打开数据库:' l4 C' A4 d7 N, ?
exec="select * from 数据库表"$ t3 R' p, i/ t2 i0 S7 f; g
set rs=server.createobject("adodb.recordset")- l5 z; {" Y+ P) x2 p/ E& \- Q
rs.open exec,conn,1,1
% X( `6 R8 v- L* ]! I* Q参数1,1为读取
/ G, t: V- y* h& X/ o
% M# ], r* P2 g7 Q1 b" O8 r; u读取内容格式:<%=rs("字段")%>
; |, H: M8 ~5 {# H0 a) h- ?0 u9 W' L# _6 S6 g
添加记录处理程序:5 J" T4 `# H7 x
<%$ }3 n9 W! K# l8 p3 s7 c
set conn=server.createobject("adodb.connection")5 d+ z2 Y2 L! h
conn.open "driver={microsoft access driver (*.mdb)};dbq="&server.mappath("数据库名")' N! t' l# `- Z! C
name=request.form("字段") name,tel,message为提交表单所设置的字段值
' y! d$ {0 D) Y- S; Ftel=request.form("字段")
1 N5 {- W1 h: A' dmessage=request.form("字段")
B% v6 \" t3 e# X, Y6 a+ fexec="insert into 表名(字段)values('"+字段+"')" 多个用逗号隔开
* X$ T! D" D, N4 z. gconn.execute exec 使用execute提交( s& W7 @/ p' K! }$ N& P0 t
conn.close
1 R, `1 S* v4 i* U9 k9 aset conn=nothing
; @9 L8 R# v& u3 i! K7 l: S" R%>- m1 S6 j0 ^- z( r1 l
1 i _3 L+ B# y* y- m( @8 ?搜索处理程序:6 J! K3 i4 f" \; X6 F; i$ S6 h/ ]
<%
7 y' ]0 ?4 Z }; u$ o( Hname=request.form("字段") name,tel为提交表单所设置的字段值+ b0 z* k4 E7 X$ R4 o% h* T
tel=request.form("字段")
& L; p5 L9 _2 p; tset conn=server.createobject("adodb.connection")
2 U: j9 M$ h" ~! W' o& qconn.open "driver={microsoft access driver (*.mdb)};dbq="&server.mappath("数据库名")
' `9 |! L9 X: A+ v0 d( b& yexec="select * from 表 where name='"+字段+"' and tel="+字段# c2 w, D+ |* `3 Z3 M* ?
set rs=server.createobject("adodb.recordset")
2 |% D- \$ {* W7 b7 Prs.open exec,conn,1,1- b$ Q- F$ u2 H% k
%>) F2 a6 v) D6 ^
'页面搜索到的内容导出来
- n* j2 u ~4 ]# e<%% E7 P* N* B& k3 {5 I, o" c
do while not rs.eof
b4 H. q- X, b3 J5 \%><tr>
- t$ w; p4 Q# f3 g' L: E4 m<td><%=rs("name")%></td>
$ e* d6 L n& p6 B, S3 z( [<td><%=rs("tel")%></td>
3 D# V3 ~- R9 [<td><%=rs("time")%></td>+ r6 u5 I+ B" G( t
</tr>, ?. J/ o2 Z8 M5 K) B' O
<%& _+ H: N; Y {
rs.movenext
$ w% D( Y5 S, Eloop% O; g7 Q) t0 U
%>5 `9 G' o2 [2 B6 _5 x# q
" F& i# p i/ W1 G9 B h删除记录处理程序:
9 W- f/ S- H8 R- l<%
- \0 \9 W8 A' V( {5 lset conn=server.createobject("adodb.connection")5 L$ ~$ ]! [; l
conn.open "driver={microsoft access driver (*.mdb)};dbq="&server.mappath("数据库名")
x8 ~! n; J5 s+ {exec="delete * from 表名 where 编号="&request.form("id")
5 A0 L' T- ^* _9 j, U) @* `, Bconn.execute exec
. q; h* e* n2 z' |" M; X%>
1 P: b2 ]) |: \" t- n" `
' r; \, G& H7 N$ [( }5 W7 X( [0 J: K+ R
修改记录处理程序:
7 @8 G, b M6 [% f7 x<%4 O3 _! f: b' n8 w2 k
set conn=server.createobject("adodb.connection")
! a4 U$ @1 n; U7 Pconn.open "driver={microsoft access driver (*.mdb)};dbq="&server.mappath("数据库名"). u/ ?# b# v/ |3 T2 Q) ]
exec="select * from 表名 where 编号="&request.form("id")
* S3 \( y/ Q8 a8 r N) uset rs=server.createobject("adodb.recordset")
$ x+ p8 b' l) A) V+ H. wrs.open exec,conn,1,3 '1,3为修改意思" n& }8 t6 ~8 s. j8 V
rs("name")=request.form("字段") 'name,tel,message为提交表单所设置的字段值 r# n5 ^# P0 S3 H
rs("tel")=request.form("字段")/ s0 B" O. W( A8 R$ ?0 a
rs("message")=request.form("字段")
; ^& n5 K; U$ \' m4 Nrs.update( w3 j$ F/ \# ^
rs.close; r6 Y# O& s+ N5 a3 D6 d- O
set rs=nothing
5 N5 r9 G8 T% Q5 qconn.close) [& U4 K3 p( O: |8 @1 D
set conn=nothing
, Q8 Z% i9 Y* J# d1 X4 a4 T%>
# s2 j) `- A$ {+ S* Q修改记录执行程序:输入ID号页面>>>导出相对应ID数据>>>>>>直接修改的处理程序$ @ U: l4 X2 {! i, p1 a
# S' X* w6 ]2 d1 H- E1 }
后台登陆处理程序例子:! e: w- [5 U6 m* q
<%7 z0 a4 d% w+ @4 [5 u
dim name,password
8 e. g( f/ i* s& v, hname=request.form("name")
3 L0 l$ f Q; M+ l7 ?% k- e* Npassword=request.form("password")1 I+ e/ D% V* r. x. p
dim exec,conn,rs6 I& x: p$ Q- m5 z7 @
exec="select *from 表名 where(name='"&字段&"' and password='"&字段&"')"
2 t+ { I7 }& V7 Q4 e& L: lset conn=server.createobject("adodb.connection")
$ \/ W; Y2 ^/ s) n3 h0 \8 I$ lconn.open "driver={microsoft access driver (*.mdb)};dbq="&server.mappath("数据库名")+ I4 u+ K* x9 e# @1 X
set rs=server.createobject("adodb.recordset")+ f) _6 G$ ~% ]( Q
rs.open exec,conn& \! @9 ]4 a+ r3 t, f7 y
if not rs.eof then: t: u: H7 h" @ D, \( Z6 r
rs.Close* E& [ b" i. K) Z" A! p9 j5 K; m: S) M
conn.Close% a4 |+ |' d# g. O5 f
session("checked")="yes"+ S4 c/ H: L( V7 ?
session("check")="right"
+ i* k, t1 m% O* n1 Gresponse.Redirect "index.asp"
( a: w0 K* U7 p0 h& o( Telse$ ~8 C4 f) {) l0 w/ N. j$ d6 e
session("checked")="no"9 o, ]1 r" a0 W# U( [
session("check")="wrong"
8 p7 L0 ]9 d* j3 Kresponse.Redirect "login.asp"+ K# f) I1 Q: M4 T- [: M( G, E
end if
. }# K8 n$ G1 w; }4 s* f4 R%>0 Y5 r! l5 q% k) n7 D" B! B( M
: e8 [, i: ?0 e, _9 n" Q2 p
每个后台页面加上:7 y& [$ y7 ]' W# W( [% U
<%if not session("checked")="yes" then 'session里面定义一个checked字符串变量" b! s6 h+ g2 O
response.Redirect "login.asp" ! \$ T% R m! N# o
else
- k. j* f: W [/ Z%> |
|