Ӧо
APPLICATION RESEARCH OF COMPUTERS
2000Vol.17No.5P.81-83



ASP+ADOվݿ
Ǳ
ժ  Ҫ  ĽΪϵͳؽASPվݿķͼɣʵ˵
ؼ  ASP  ADO  վݿ
1  ASPʶ
Active Server Pages (̬ҳASP)ںInternet Information Server (IIS)Уṩһ(Server-side)Scriptingִж̬ʽЧʵվӦó򣬲ʹվԶActive Server PagesĳΪ׼HTMLʽݣ͵û˵ʾûֻҪʹóִHTMLActive Server PagesƵҳݡ
ASPصǣ
(1)HTMLУ뼴ִУ
(2)ʹóı༭Windowsļ±ƣ
(3)޹(Browser Independence)ûֻҪʹóĿִHTMLASPƵҳݣScript(VBscriptJscript)վ(Server)ִУûҪִЩScriptԣ
(4)(Object_Orient)
(5)ͨActiveX Server Components (ActiveX)书ܡActiveX Server componentsʹVisual BasicJavaVisual C++COBOLʵ֣
(6)ASPκActiveX ScriptingԼݡ˿ʹVBscriptJscript⣬ͨPlug-inķʽʹɵṩƩREXXPerlTclScriptingԡScriptǴScriptCOM (Component Object Model)
(7)ASPԴ룬ᴫû˿ԱдԴ򡣴ûASPִнĳHTML룻
(8)ʹ÷ScriptͻScriptʹASP룬վִScript(VBscriptJscript)ڿͻִеScriptԡ
ASPṩõġ(Object)ֱӵã
RequestȡûϢ
ResponseϢû
Serverṩʷķ(methods)(properties)Ĺܣ
ApplicationһӦó򣬿ڶҳ֮䱣ʹһЩͬϢ
Sessionһûڶҳ֮䱣ʹһЩͬϢ
ASPļչ.aspһıļASPļаHTML(tags)VBscriptJscriptԵĳ롢ASP﷨
ASPһScriptԣṩһԼScript(VBscriptJscript)HTMLҳĻHTML(tags)ʹá<...>HTML볣ıֿASPʹá<%...%>ASPScript
2  ASP+ADOվݿĲ
ADO΢ṩվݿʼASPһͨODBCӦݿ⡣ASPݿĹǣWebһASPļʱWebASPļȻִÿһű䣬ADOͨODBCݿ⣬ִٰеĽHTMLļͻˡ
ADOݿƲ裺
(1)趨ODBCݿӡNTִС塱ϵġODBCѡϵͳDSNӡťѡԴѡSQL ServerȻԴ(DSN)ݿơ
(2)ʹáServer.createobjectӵĶ󣬲ʹáOpen򿪴ʲѯݿ⡣
set conn=server.createobject(adodb.connection)
conn.openݿƣ
ݿƼΪڡODBC趨ġԴơ
(3)趨SQLʹáExecuteʼִзʲѯݿĶ
set rs=conn.execute(SQL)
(4)ʹrecordsetsʾѯĽ
.rs.fields.count: recordsֶ;
.rs(i).name: i(ָ)ֶi0rs.fields.count-1;
.rs(i): ȡi(ָ)ֶεļ¼i0rs.fields.count-1;
.rs(ֶ&quot;): ȡֶָεļ¼;
.rs.eof: (true)(false)ָĩ;
.rs.movenext: ָƵһ;
.rs.moveprev: ָƵһ;
.rs.movefirst: ָƵһ;
.rs.movelast: ָƵĩ;
.rs.getrows: ѯ鵱Уv=rs.getgows(100)ٶȡv(col, row)ֵΪѯļ¼;
.rs.properties.count:õADOConnectionResultset;
.rs.properties(item).name: õADOConnectionResultset;
.rs.properties(item): õADOConnectionResultsetֵ
(5)ʹµرݿ⡣
rs.close
conn.close
3  һѯϵͳ
search.aspļFormγһѯ(ͼ1ʾ)ûѡ˲ѯ󣬰¡ύť͵process.aspУprocess.aspݱֵSQLڷݿļĲѯ󽫲ѯͻ(ͼ2ʾ)

ͼ1

ͼ2
search.aspԴ룺
<html>
<head>
<title></title>
<meta content="text/html; charset=gb2312" http-equiv="Content-" Type>
<style>
body {font-size:9pt;background-attachment:fixed}
table{font-size:9pt) </style>
<script language="vbscript">
sub back
history.back
end sub
sub forward
history.forward
end sub
</script>
</head>
<body aLink="#FF6666" background="Image/nabkgnd.jpg" bgColor="#ffffff" link="#FF3333" text="#000099" vLink="#FF0066">
<div align="center"><font size="5" face="" color="#FF33FF">99ѯ</font></div>
<form method="Post" action="Process.asp" name="newstudent">
<table width="734" border="0">
<tr><td width="264"><input type="text" name="sname"></td>
<td width="233">Ա<input type="radio" name="ssex" value="" checked><input type="radio" name="ssex" value=""><input type="radio" name="ssex" value="Ů">Ů</td>
<td width="223" rowspan="2" valign="top">רҵ<select name="sdpm">
<option value="" selected></option><option value="Ź">Ź</option>
<option value=""></option>  <option value=""></option>
<option value="ѧ">ѧ</option>  <option value="ѧ">ѧ</option>
<option value="뱣">뱣</option> <option value="ͨѶ">ͨѶ</option>
</select></td></tr>
<tr><td width="264" rowspan="2">ҵѧУ<input type="text" name="sschool"> </td>
<td width="233" rowspan="2">ط<input type="text" name="sarea"></td> </tr>
<tr><td width="223" valign="top"><input type="text" name="sbelong"> </td> </tr>
</table>
<div align="center"> <table width="524" border="0">
<tr><td> <div align="center"><input type="submit" value="ύ"></div></td>
<td> <div align="center"><input type="reset" value=""></div></td> </tr> </table> </div>
</form>
<br><br><br><div align="center">
<table width="500">
<tr> <td width="*" align="left"><img src="/Image/back.gif" alt="back" border="0" onclick="back(" )></td>
<td width="200" align="center"><a href="/index.html#startpage&quot;"><img src="/Image/home.gif" alt="home" border="0" width="30" height="30"></a></td>
<td width="*" align="right"><img src="/Image/forward.gif" alt="forward" onclick="forward(" ) width="50" height="30"></td></tr></table></div>     </body> <[html>
process.aspԴ:
<html>
<head>
<title></title>
<meta content="text/html; charset=gb2312" http-equiv="Content-" Type>
<style>
body{font-size:9pt;background-attachment:fixed)
table{font-size:9pt)
</style>
<script language="vbscript">
sub back
history.back
end sub
sub forward
history.forward
end sub
</script>
<%
Sub combinesql (psql)
bsql=""
if (request.form("sname")<>"") then
if (bsql<>"") then
bsql=bsql &"and"
end if
bsql=bsql&"="'&request.form("sname")&""'
End if
if (request.form("ssex")<>"") Then
if (bsql<>"") then
bsql=bsql&"and"
end if
bsql=bsql&"Ա="'&request.form("ssex")&"'"
end if
if (request.form("sdpm")<>"") then
if (bsql<>"") then
bsql=bsql&" and"
end if
bsql=bsql&" רҵ like '%"&request.form 
("sdpm")&"%"'
End if
if (request.form("sscholl")<>"") then
if (bsql<>"") then
bsql=bsql&" and"
end if
bsql=bsql&"ҵѧУlike'%"&request.form 
("sscholl")&"%"'
end if
if (request.form("sarea")<>"") then
if (bsql<>"") then
bsql=bsql&" and"
end if
bsql=bsql&"ط like'%"&request.form
("sarea")&"%'"
end if
if (request.form("sbelong")<>"") then
if (bsql<>"") then
bsql=bsql&" and"
end if
bsql=bsql&" like'%"&request.form
("sbelong")&"%"'
end if
if (bsql<>"") then
psql=psql&" where ("&bsql&")"
end if
End Sub
%>
</head>
<body aLink="#FF6666" background="Image/nabkgnd.jpg" bgcolor="#ffffff" link="#FF3333" text="#000099" vLink="#FF0066"> <font face="_GB2312" size="4" color="#FF0000">ѯ: 
</font><br>
<%
set dbf=server.createobject ("adodb.connection")
dbf.open ("stud")
sql="select * from ѧԺ99.dbf "
call combinesql (sql)
response.write ("ѯ:"&sql&"<br><hr>")
set rs=dbf.execute(sql)
if rs.eof then
response.write ("Nobody was found ! <FONT COLOR=RED>TRY 
AGAIN! </FONT><br><hr>")
else
response.write("鵽"&rs.recordcount&"¼!")
%>
<table width="750" border="0">
<% do while not rs.eof %>
<tr><td width="120">:<%response.write(rs("")) %></td>
<td width="120">:<% response.write(rs("")) %></td>
<td width="120">Ա:<% response.write(rs("Ա")) %></td>
<td width="61">:<% response.write(rs("")) %></td>
<td width="179">:<% response.write(rs("")) %></td>
<td width="124">:<% response.write(rs("")) %></td> </tr>
<tr> <td width="120">רҵ:<% response.write(rs("רҵ"))%></td>
<td width="120">:<% response.write(rs("")) %></td>
<td width="120">:<% response.write(rs("")) %></td>
<td width="364" colspan="3">ط:<% response.write(rs("ط")) %></td> </tr>
<tr> <td width="360" colspan="3">ҵѧУ:<% response.write 
(rs("ҵѧУ")) %></td>
<td width="364" colspan="3">ͥסַ:<% response.write 
(rs("ͥסַ")) %></td></tr>
<tr> <td width="724" colspan="6"> <hr> </td> </tr>
<%
rs.movenext
loop
rs.close
dbf.close
end if
%> </table>
</body>
</html>
4  
ͨʵ˵ASP+ADOվݿļǷǳѧõģҾиЧ١ȫԣһּ߷չǱ¼
Ǳ(ɶƼѧ  ɶ 610065)
(ɶѧԺϵ  ɶ 610041)
ο
1̵, ʹ. ASPʵWebĶ̬. Ӧо, 1999.2, 6264
2http://www.swm.com.cn/yingyong/rj-98-yy2/98-y2-yy17.htm
ոڣ1999-11-16
