—- 本文着重介绍通过iis4.0服务管理中asp脚本语言实现访问access数据库,至于如何创建系统dsn这里一带而过,有兴趣的读者自己可以去试一试。
—-首先,创建一个access数据库,其中含有姓名、部门名称、部门费用的字段名。
—-其次,在安装iis4.0的www服务器上,打开odbc,创建系统dsn,数据源名abc,选取对应的access数据库,建立好后就可以开始写asp程序了。
—-根据需要我们想对access数据库中的部门名称按照不同的部门进行查询,按照费用金额的大小进行查询。
—-按照部门名称查询创建shujuku5.asp,asp的程序源代码如下:
< html >
< body >
< %
set connect=server.createobject(“adodb.connection”)
connect.open “abc”
s=request(“menu1″)
sql=“select * from sheet1 where
部门名称=”&“‘”&s&“”
set rs=connect.execute(sql)
%>
< table border=1 cellspacing=1 >
< tr bgcolor=“#00ffff” >
< %for i=0 to 7% >
< td size=1 > < b >< %=rs(i).name% >< /b >
< td >< %next% >
< tr >
< %do while not rs.eof% >
< tr >
< %for i=0 to 7% >
< td size=1 >< %=rs(i)% >< td >
< %next% >
< /tr >
< %rs.movenext
loop
% >
< %
rs.close
connect.close
% >
< /table >
< /body >
< /html >
—-按照费用金额创建shujuku4.asp,asp源代码程序如下:
< html >
< body >
< %
set connect=server.createobject(“adodb.connection”)
connect.open “abc”
r=request(“textfield”)
s=request(“menu2″)
if s=“大于” then
sql=“select * from sheet1 where 费用金额 >”&r&“”
elseif s=“小于” then
sql=“select * from sheet1 where 费用金额< “&r&“”
elseif s=“等于” then
sql=“select * from sheet1 where 费用金额=”&r&“”
elseif s=“大于等于” then
sql=“select * from sheet1 where 费用金额 >=”&r&“”
elseif s=“小于等于” then
sql=“select * from sheet1 where 费用金额< =”&r&“”
end if
set rs=connect.execute(sql)
% >
< table border=1 cellspacing=5 >
< tr bgcolor=“#00ffff” >
< %for i=0 to 7% >
< td >< b >< font size=“2″ >< %=rs(i).name% >
< /font >< /b >
< td >< %next% >
< tr >
< %do while not rs.eof% >
< tr >
< %for i=0 to 7% >
< td size=8 >< %=rs(i)% >< td >
< %next% >
< /tr >
< %rs.movenext
loop
% >
< %
rs.close
connect.close
% >
< /table >
< /body >
< /html >
—-创建好这两个asp文件拷贝到iis4.0的虚拟目录 wwwroot下,然后再用frontpage、dreamweaver编写一个html程序 bumenfeiyong.html,其源代码程序如下:
< html >
< head >
< title >untitled document< /title >
< meta http-equiv=“content-
type” content=“text/html; charset=gb2312″ >
< /head >
< body bgcolor=“#ffffff” >
< div align=“center” >
< p >< b >< font color=“#cc3333″ size=“5″ >
部门费用查询< /font >< /b >< /p >
< p >< img src=“trees.gif” width=“600″ height=“17″ >
< /p >
< table width=“100%” border=“1″ cellspacing=“10″
bordercolor=“#ffffff” >
< tr bordercolor=“#ffcccc” >
< td height=“9″ >
< form method=“post” action=
“http://192.1.168.100/shujuku5.asp” >
< select name=“menu1″ >
< option selected >按部门查询< /option >
< option >总经理室< /option >
< option >财务部< /option >
< option >市场部< /option >
< option >物配部< /option >
< option >销售部< /option >
< option >办公室< /option >
< /select >
< input type=“submit” name=“submit” value=“提交” >
< /form >
< /td >
< /tr >
< tr bordercolor=“#ffcccc” >
< td height=“15″ >
< form method=“post” action=
“http://192.1.168.100/shujuku4.asp” >
< select name=“menu2″ >
< option selected >费用金额< /option >
< option >大于< /option >
< option >大于等于< /option >
< option >等于< /option >
< option >小于等于< /option >
< option >小于< /option >
< /select >
< input type=“text” name=“textfield” size=“12″ >
< input type=“submit” name=“submit2″ value=“提交” >
< /form >
< /td >
< /tr >
< tr bordercolor=“#ffcccc” >
< td >&nbsp;< /td >
< /tr >
< tr bordercolor=“#ffcccc” >
< td >&nbsp;< /td >
< /tr >
< tr bordercolor=“#ffcccc” >
< td >&nbsp;< /td >
< /tr >
< tr bordercolor=“#ffcccc” >
< td >&nbsp;< /td >
< /tr >
< tr bordercolor=“#ffcccc” >
< td >&nbsp;< /td >
< /tr >
< /table >
< p >&nbsp;< /p >
< /div >
< /body >
< /html >
—-通过以上程序的编写,再用ie5.0打开bumenfeiyong.htm 后,根据画面输入您想要得到的查询,每个部门得到不同的查询结果。在费用金额选取大于、小于、等于等选择条件,后面选取金额,就能得到大于、小于、等于某一数值的查询结果。读者还可以根据自己的需要添加更多的字段,完成不同字段的查询,其asp源代码与以上程序大同小异。