|
Asp:实现对SQL SERVER 数据库的操作
---- 目前管理信息系统已从传统的客户机/服务器(C/S)模式转向了浏览器/服务器(B/S)模式,特别是微软公司推出它的新产品ASP语言之后,这种转变更加迅猛。管理信息系统的核心是对数据库进行包括添加、修改和查询等等操作,ASP提供的ADO数据库接口控件,使得程序员再也勿需编写复杂的CGI程序了,而只要用几句简单的语句即可实现以上操作。目前有很多介绍用ASP开发网络数据库的程序例子,但绝大部分是利用ACCESS作底层数据库。相对于ACCESS而言,SQL SERVER数据库系统要复杂得多,因此在程序开发中需要多做一些工作。笔者结合自己开发管理信息系统的经验,在此试举一例,与感兴趣的朋友共同交流。
---- 1、系统环境
---- PII 350,Ram 64M,WINNT Server 4.0,
Service Pack4, IIS 4.0, SQL Server7.0。
---- 2、系统功能
---- 通过使用IE浏览器,在网上实现对《办公文件》数据表记录的添加和查询。
---- 3、功能实现
---- (1)数据表的设置
---- ①启动SQL Server7.0的Enterprise Manager,
在Databases 目录下增加一个新子目录"test";
---- ②在"test"下增加一个new table,名为"办公文件",字段设置:文件名,char,100,允许空;文件内容,char,4000,允许空。
---- ③在SQL Server中增加一个用户,名为hxl, 密码为123,登录模式为SQL 登录,将其默认登录数据库设为"test";
---- ④在"test"数据库下增加一个新用户,名为hxl,其角色设为"Dbowner"。
---- (2)ODBC 链接
---- ①在控制面板中,打开ODBC数据源,选择系统DSN项,单击"添加";
---- ②选择"SQL Server"数据源,命名为"test";
---- ③选择登录模式为SQL Server验证,登录标志为"hxl",密码为"123";
---- ④将默认数据库高为"test",再测试数据库链接,接通即可。
---- (3)程序文件
---- 为了实现系统功能,在这里编辑了3个程序文件,分别为"index.html"、"add.asp"和"query.asp",具体内容如下:
---- ①index.html:系统首页,包括两个选项,一是追加记录,二是查询,用户可单击两者之一,即可进入相应的操作过程。以下是源程序:
< html >
< head >
< meta http-equiv=\"Content-Language\"
content=\"zh-cn\" >
< meta http-equiv=\"Content-Type\"
content=\"text/html; charset=gb2312\" >
< meta name=\"GENERATOR\" content=\"Microsoft
FrontPage 4.0\" >
< meta name=\" rogId\" content=\"FrontPage
.Editor.Document\" >
< title >示例程序< /title >
< /head >
< body >
< p align=\"center\" >
< font size=\"5\" color=\"#008000\" >
欢迎使用用ASP语言对SQL
SERVER数据库操作示例< /font >< /P >
< p align=\"center\" > < /P >
< p align=\"center\" >< a href=\"add.asp\" >
追加记录< /a >< /p >
< p align=\"center\" >< a href=\"query.asp\" >
查 询< /a >< /p >
< /body >
< /html >
---- ②add.asp:实现对《办公文件》数据表记录的添加。页面中含有一个单行文本框
(Txtbiaoti)和一个滚动文本框(Txtneirong),分别用来输入文件标题和文件内容。此外,页面中还应有两个按钮,"确定(Cmdok)"和"重写(Cmdcancel)",单击"确定"完成记录追加,单击"重写"重新输入内容。以下是源程序:
< html >
< head >
< meta http-equiv=\"Content-Type\"
content=\"text/html; charset=gb2312\" >
< meta name=\"GENERATOR\" content=
\"Microsoft FrontPage 4.0\" >
< meta name=\"ProgId\" content=
\"FrontPage.Editor.Document\" >
< title >追加一条新记录< /title >
< /head >
< body >
< % if request.form(\"cmdok\")=\"确定\" then % >
< %
set dbconnection=server.createobject
(\"adodb.connection\") dbconnection.open\"test\",\"hxl\",\"123\"
sqlquery=\"insert \"办公文件\"
(文件名,文件内容)
values ('request.form(\"Txtbiaoti\")','
request.form(\"Txtneirong\")')
set recadd=dbconnection.execute(sqlquery) % >
< % else % >
< p align=\"center\" >追加记录< /p >
< form method=\"POST\" action=\"\" >
< p >文件名:< input type=\"text\"
name=\"Txtbiaoti\" size=\"20\" >< /p >
< p >文件内容:< /p >
< p >
< textarea rows=\"3\"
name=\"Txtneirong\" cols=\"60\" >< /textarea >
< /p >
< p align=\"center\" >< input type=\"submit\"
value=\"确定\" name=\"Cmdok\" >
< input type=\"reset\" value=\"重写\"
name=\"Cmdcancel\" >
< /p >< /form >
< % end if% >
< /body >
< /html >
---- ③query.asp:实现对《办公文件》数据表记录的查询。程序仅实现对《办公文件》中"文件名"的查询,查询结果用一个表单(Table)列出。以下是源程序:
< html >
< head >
< meta http-equiv=\"Content-Type\"
content=\"text/html;charset=gb2312\" >
< meta name=\"GENERATOR\" content=\"Microsoft
FrontPage 4.0\" >
< meta name=\"ProgId\" content=
\"FrontPage.Editor.Document\" >
< title >检索文件< /title >
< /head >
< body bgcolor=\"#ffffdd\" >
< %
set dbconnection=server.createobject
(\"adodb.connection\")
dbconnection.open \"test\",\"hxl\",\"123\"
sqlquery=\"SELECT 文件名 FROM 办公文件 \"
set resultlist=dbconnection.execute(sqlquery)
% >
< center >
< font color=\"red\" >< %=request(\"selectsource\")% >
< /font >< font color=\"#008000\" size=\"5\" >< b >
有以下文件可供阅览< /b >< /font >
< hr size=\"5\" >
< table border=\"1\" >
< tr >
< td width=\"200\" align=\"center\" > < b >
文件名 < /b > < /td >
< /tr >
< % do while not resultlist.eof % >
< tr >
< td valign=center width=\"200\" >< %=resultlist
(\"文件名\")% >< /a >< /td >
< /tr >
< %
resultlist.movenext
loop
resultlist.close
% >
< /center >
< /TABLE >
< /body >
< /html >
---- 4、总结
---- 用IE打开index.html或将文件发布到站点,进行相应的操作,即可实现对SQL Server数据库系统中《办公文件》数据表记录的追加和查询,至此系统目标已经达到。 |
广告, 技术, 空间, 系统, 服务器, 教程, 破解, 服务器, 诺德尔, 破解, 3389, 服务器, 锐起, 网吧, 无盘, 教程, 绿茶, 诺德尔, 软件, 系统, 诺德尔, 绿茶, 系统, FTP, Windows, 系统, 电脑, 教程, 网络, ROS, ROS, ROS, 路由, 路由, linux, 网络,
|