TA的每日心情 | 衰 2019-8-18 09:37 |
---|
签到天数: 2 天 [LV.1]初来乍到
|
数据库连接:1 o/ {0 q/ [+ \. J' Q, L) x, j
<%$ {2 O3 [6 W- }/ f0 O
set conn=server.createobject("adodb.connection")& |4 l' i5 Y3 \; L a
conn.open "driver={microsoft access driver (*.mdb)};dbq="&server.mappath("数据库名")% X' ?4 i# q H( z; X
%>
1 E, Z1 \ |- n# ?, S/ x1 U5 t- r, `; F9 v! c' E* |
1 C9 q( \$ [8 B: e& P6 v7 h打开数据库:
/ W: z1 f Z$ o" N+ { sexec="select * from 数据库表"
& x: \& ^9 a3 j/ s! z7 L( [set rs=server.createobject("adodb.recordset")' c% k/ d1 |# f
rs.open exec,conn,1,1
G( L: K6 E* e) U/ p! U- ~% r' x参数1,1为读取
; O; A8 i$ k! d; t9 d/ X# b( I: s/ `" `8 C6 x
读取内容格式:<%=rs("字段")%>
7 l' R6 ]$ g" w; A% c7 E% K& @7 h; z4 C1 }
添加记录处理程序:% @9 ?( U/ P; i" q! B
<%
; @" [2 y' n7 E3 ?; } k W C" Xset conn=server.createobject("adodb.connection")
5 o% r5 `4 ~5 {conn.open "driver={microsoft access driver (*.mdb)};dbq="&server.mappath("数据库名")6 g/ C) ~; ^3 D( N) F
name=request.form("字段") name,tel,message为提交表单所设置的字段值6 F+ n- F4 t8 h8 @6 n2 N/ h0 c
tel=request.form("字段")
. y: l0 `! x, o( W& amessage=request.form("字段")
. M2 G/ W& d" ~. t* Z& }exec="insert into 表名(字段)values('"+字段+"')" 多个用逗号隔开7 n# n3 j( G7 b4 e: p( [
conn.execute exec 使用execute提交
9 T* R5 N9 o" oconn.close
5 R3 g( y7 m" g* t5 x! \$ fset conn=nothing' ?/ _7 y% r. q- a* E
%>1 d/ ~3 e$ z( u8 J( `. J2 @+ q
" ], n# u7 J" j8 U+ Y
搜索处理程序:
- ~" W4 O" j4 V0 z7 I- c/ Y1 T<%% F8 u& ^$ l! }0 R* f6 ]- ]4 ~
name=request.form("字段") name,tel为提交表单所设置的字段值
: Y5 q7 R& \) s7 _tel=request.form("字段")
) C5 a* b) r4 W/ dset conn=server.createobject("adodb.connection")
) U8 `5 P/ ?" g( Mconn.open "driver={microsoft access driver (*.mdb)};dbq="&server.mappath("数据库名")0 ?2 F* k" |& {, A
exec="select * from 表 where name='"+字段+"' and tel="+字段
) B! x) L8 l) p5 hset rs=server.createobject("adodb.recordset")
, k5 ]3 z* }$ t, W$ \, }, B Z: Crs.open exec,conn,1,1
# a& T) m! t+ n2 r* J%>
9 I. Q6 |* c8 }: v'页面搜索到的内容导出来+ e' h" E a6 O s
<%8 I: l ~9 k( }9 W7 t7 ~
do while not rs.eof
7 n, g" S& z3 r e$ D1 d%><tr>
- @0 V) |" U: }& s4 |<td><%=rs("name")%></td>
. v4 Y4 S- B4 U& m" E" H<td><%=rs("tel")%></td>
4 y- Y0 h% P( r1 r/ p5 J9 r: j<td><%=rs("time")%></td>
7 [; O5 C e! t- W+ G8 b0 ?</tr>
% q- X- F$ y" j$ d0 b3 z<%: V' @" X9 Q+ T% E9 t% s; L
rs.movenext
7 x/ ?8 [6 l. O9 v' x! a4 lloop
0 t* F; O: ?4 T, C; U3 R%># j9 K1 ?* Z O) l& h! w" a' k; r- M8 \
6 A. Z; o; E5 }2 d7 V7 \3 O删除记录处理程序:& {' y" E4 Y* c4 q
<%
- {3 y( N2 M3 n* Aset conn=server.createobject("adodb.connection")7 }/ G% M, m% |+ S5 I" W4 t9 v
conn.open "driver={microsoft access driver (*.mdb)};dbq="&server.mappath("数据库名")
- m/ p" W0 }; ~6 I4 [. w' z: Vexec="delete * from 表名 where 编号="&request.form("id")
6 l3 g. `) I- u I Pconn.execute exec# [$ }! s% A& S5 i" v, F6 G
%>$ @& l2 O3 J, k* _
) @6 }! S2 `8 C' B" G s
" o- j6 O1 F' m6 I# J4 s& _% O修改记录处理程序:. x0 x |" c8 I; p, Y
<%
6 b% `8 v) g+ W6 Hset conn=server.createobject("adodb.connection")
- M9 L* J/ A7 ~conn.open "driver={microsoft access driver (*.mdb)};dbq="&server.mappath("数据库名")/ l0 c& S* ^/ g2 g% ] ^2 m
exec="select * from 表名 where 编号="&request.form("id")/ h; W) p# L% R% h8 ] g- I, c
set rs=server.createobject("adodb.recordset")
U2 w% C6 G$ X/ A9 M; G5 d" ]rs.open exec,conn,1,3 '1,3为修改意思+ V( P6 l* I! s/ u( x
rs("name")=request.form("字段") 'name,tel,message为提交表单所设置的字段值6 j& ~& k& p3 |4 m. ]% Z2 |3 i/ z
rs("tel")=request.form("字段")7 E' d( P( }1 ^+ b
rs("message")=request.form("字段")4 O9 Z: n$ |, Z+ U# L- d8 A5 @
rs.update
o; ^1 s8 V& zrs.close
# |+ H' X ^5 R/ [set rs=nothing
, P9 Q6 c! C. c z) I3 v4 zconn.close4 Z- b4 G1 H& w9 r* B0 P9 s
set conn=nothing4 a7 {; |" ~2 U( M/ _' ^
%>! T3 G1 P9 ^$ G1 I; h7 N- l
修改记录执行程序:输入ID号页面>>>导出相对应ID数据>>>>>>直接修改的处理程序
" f8 N, [6 O, l/ b
5 V3 E/ o; Q- I) Q! r/ u后台登陆处理程序例子:
) p# x1 ?1 E/ [* w<%
1 ^8 [7 f$ C5 V" ~! b6 hdim name,password
, g0 G$ Q* h- Y H/ Uname=request.form("name")
j' c* Z3 T" x/ Y6 Jpassword=request.form("password")! ^& ~) \! M( N0 @$ C; G" u
dim exec,conn,rs
7 l+ I. G& _; {; l. \4 ]1 s. g5 zexec="select *from 表名 where(name='"&字段&"' and password='"&字段&"')"
& v9 Z) _6 M0 Wset conn=server.createobject("adodb.connection")
; w A* a3 d6 Q$ e' U0 kconn.open "driver={microsoft access driver (*.mdb)};dbq="&server.mappath("数据库名")0 h! \" I+ o. c) B7 N. _2 L% d
set rs=server.createobject("adodb.recordset")3 f- [" a$ Z' V- ^( i' j
rs.open exec,conn
& n1 @/ @* K, Z5 i* a- Q- kif not rs.eof then; a4 c' k. U. K) d: @
rs.Close
/ O% V5 A" x6 w1 }: n! Z2 Econn.Close+ E) ]" `, ^. @
session("checked")="yes"& h6 j: D2 v# |# S h2 B
session("check")="right"
4 @# E; w! @- f& v2 Wresponse.Redirect "index.asp"
1 q7 n, q+ w1 M) E* X& Eelse
) ~; P' p" K W: hsession("checked")="no"3 r2 \, ?5 u5 h$ p8 s
session("check")="wrong"
" ^% e, _- }) `response.Redirect "login.asp"+ J/ w- Q' s9 U
end if' D) s( ]1 Y9 ?( R L; @% N' j0 M9 ~
%>
- P$ A3 T5 K+ @2 P- a. |0 e5 y4 P0 Y4 X6 Z2 _9 V. O# S
每个后台页面加上:6 w2 ]& Q# U: M% F. F' y. H7 G
<%if not session("checked")="yes" then 'session里面定义一个checked字符串变量
6 ?* @$ r: G; N0 g9 }response.Redirect "login.asp"
6 ~0 d. x' z( v) g- L6 |else$ P) Z) M2 N; o+ F$ O8 M
%> |
|