目前管理信息系統(tǒng)已從傳統(tǒng)的客戶機(jī)/服務(wù)器(C/S)模式轉(zhuǎn)向了瀏覽器/服務(wù)器(B/S)模式,特別是微軟公司推出它的新產(chǎn)品ASP語言之后,這種轉(zhuǎn)變更加迅猛。管理信息系統(tǒng)的核心是對(duì)數(shù)據(jù)庫進(jìn)行包括添加、修改和查詢等等操作,ASP提供的ADO數(shù)據(jù)庫接口控件,使得程序員再也勿需編寫復(fù)雜的CGI程序了,而只要用幾句簡單的語句即可實(shí)現(xiàn)以上操作。
1、系統(tǒng)環(huán)境
PII 350,Ram 64M,WINNT Server 4.0,
Service Pack4, IIS 4.0, SQL Server7.0。
2、系統(tǒng)功能
通過使用IE瀏覽器,在網(wǎng)上實(shí)現(xiàn)對(duì)《辦公文件》數(shù)據(jù)表記錄的添加和查詢。
3、功能實(shí)現(xiàn)
(1)數(shù)據(jù)表的設(shè)置
①啟動(dòng)SQL Server7.0的Enterprise Manager,
在Databases 目錄下增加一個(gè)新子目錄"test";
②在"test"下增加一個(gè)new table,名為"辦公文件",字段設(shè)置:文件名,char,100,允許空;文件內(nèi)容,char,4000,允許空。
③在SQL Server中增加一個(gè)用戶,名為hxl, 密碼為123,登錄模式為SQL 登錄,將其默認(rèn)登錄數(shù)據(jù)庫設(shè)為"test";
④在"test"數(shù)據(jù)庫下增加一個(gè)新用戶,名為hxl,其角色設(shè)為"Dbowner"。
(2)ODBC 鏈接
①在控制面板中,打開ODBC數(shù)據(jù)源,選擇系統(tǒng)DSN項(xiàng),單擊"添加";
②選擇"SQL Server"數(shù)據(jù)源,命名為"test";
③選擇登錄模式為SQL Server驗(yàn)證,登錄標(biāo)志為"hxl",密碼為"123";
④將默認(rèn)數(shù)據(jù)庫高為"test",再測試數(shù)據(jù)庫鏈接,接通即可。
(3)程序文件
為了實(shí)現(xiàn)系統(tǒng)功能,在這里編輯了3個(gè)程序文件,分別為"index.html"、"add.asp"和"query.asp",具體內(nèi)容如下:
①index.html:系統(tǒng)首頁,包括兩個(gè)選項(xiàng),一是追加記錄,二是查詢,用戶可單擊兩者之一,即可進(jìn)入相應(yīng)的操作過程。以下是源程序:
< 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="ProgId" content="FrontPage .Editor.Document" > < title >示例程序< /title > < /head > < body > < p align="center" > < font size="5" color="#008000" > 歡迎使用用ASP語言對(duì)SQL SERVER數(shù)據(jù)庫操作示例< /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:實(shí)現(xiàn)對(duì)《辦公文件》數(shù)據(jù)表記錄的添加。頁面中含有一個(gè)單行文本框(Txtbiaoti)和一個(gè)滾動(dòng)文本框(Txtneirong),分別用來輸入文件標(biāo)題和文件內(nèi)容。此外,頁面中還應(yīng)有兩個(gè)按鈕,"確定(Cmdok)"和"重寫(Cmdcancel)",單擊"確定"完成記錄追加,單擊"重寫"重新輸入內(nèi)容。以下是源程序:
< 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 "辦公文件" (文件名,文件內(nèi)容) 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 >文件內(nèi)容:< /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:實(shí)現(xiàn)對(duì)《辦公文件》數(shù)據(jù)表記錄的查詢。程序僅實(shí)現(xiàn)對(duì)《辦公文件》中"文件名"的查詢,查詢結(jié)果用一個(gè)表單(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 >
總結(jié)
用IE打開index.html或?qū)⑽募l(fā)布到站點(diǎn),進(jìn)行相應(yīng)的操作,即可實(shí)現(xiàn)對(duì)SQL Server數(shù)據(jù)庫系統(tǒng)中《辦公文件》數(shù)據(jù)表記錄的追加和查詢,至此系統(tǒng)目標(biāo)已經(jīng)達(dá)到。
以上就是用ASP語言實(shí)現(xiàn)對(duì)SQL SERVER 數(shù)據(jù)庫的操作,希望獲得更多這方面內(nèi)容的童鞋可以閱讀相關(guān)文章。