ASP快速開發(fā)方法之?dāng)?shù)據(jù)操作_ASP教程
推薦:ASP實(shí)例:即時顯示當(dāng)前頁面瀏覽人數(shù)ASP實(shí)現(xiàn)即時顯示當(dāng)前頁面瀏覽人數(shù) online.asp文件 以下為引用的內(nèi)容: <!--#include file="dbconn.asp" --> <% onlineTimeout=10
這是我自己的心得,給大家作個參考。
我的目的是讓開發(fā)變得簡單,盡可能少地考慮實(shí)現(xiàn)語句,更多地把精力用于思考業(yè)務(wù)邏輯。希望我的文章對大家有所啟發(fā)和幫助。
好吧,讓我們進(jìn)入正題:
先看以下例子:
| 以下為引用的內(nèi)容: <% db_path = "database/cnbruce.mdb" Set conn= Server.CreateObject("ADODB.Connection") connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&Server.MapPath(db_path) conn.Open connstr Set rs = Server.CreateObject ("ADODB.Recordset") sql = "Select * from cnarticle" rs.Open sql,conn,1,1 if rs.EOF and rs.BOF then response.write ("暫時還沒有文章") else Do Until rs.EOF response.write("文章標(biāo)題是:"& rs("cn_title")) response.write("<br>文章作者是:"& rs("cn_author")) response.write("<br>文章加入時間是:"& rs("cn_time")) response.write("<br>文章內(nèi)容是:"& rs("cn_content")) response.write("<hr>") rs.MoveNext Loop end if rs.close Set rs = Nothing conn.close set conn=Nothing %> |
嗯,這是一個典型的讀取數(shù)據(jù)并顯示的例子,參見:http://www.cnbruce.com/blog/showlog.asp?cat_id=26&log_id=448
嗯,確實(shí)簡單。從上至下,很容易明白。但是當(dāng)你對多個表進(jìn)行讀插刪改的時候,當(dāng)你的代碼里有很多HTML\js混雜的時候,你會有疑問:為什么有這么多東西要重復(fù)呢?
所以一般我們把一些簡單的操作獨(dú)立出來,寫成類或者函數(shù)放進(jìn)包含文件(include)。
那么以上的操作我們可以使用兩個文件來實(shí)現(xiàn):
conn.asp
| 以下為引用的內(nèi)容: <% db_path = "database/cnbruce.mdb" Set conn= Server.CreateObject("ADODB.Connection") connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&Server.MapPath(db_path) conn.Open connstr %> |
showit.asp
| 以下為引用的內(nèi)容: <!--#include file="conn.asp" --> <% Set rs = Server.CreateObject ("ADODB.Recordset") sql = "Select * from cnarticle" rs.Open sql,conn,1,1 if rs.EOF and rs.BOF then response.write ("暫時還沒有文章") else Do Until rs.EOF response.write("文章標(biāo)題是:"& rs("cn_title")) response.write("<br>文章作者是:"& rs("cn_author")) response.write("<br>文章加入時間是:"& rs("cn_time")) response.write("<br>文章內(nèi)容是:"& rs("cn_content")) response.write("<hr>") rs.MoveNext Loop end if rs.close Set rs = Nothing conn.close set conn=Nothing %> |
參考:http://www.cnbruce.com/blog/showlog.asp?cat_id=26&log_id=448
現(xiàn)在相對簡單多了,如果有多個操作頁面我們只要導(dǎo)入連接文件就可以了,不過還是不夠簡潔,哪里不簡潔?
一直在創(chuàng)建server,一直在寫close,這樣很容易出錯,并且看起來與內(nèi)容無關(guān)的太多。
分享:ASP教程:解決ASP腳本運(yùn)行超時的方法最近在學(xué)習(xí)服務(wù)器知識。有時候遇到asp腳本運(yùn)行超時的錯誤,真是麻煩。找了相關(guān)資料,其中有一些解決方法。 IIS默認(rèn)的腳本超時時間是90秒 這樣的話如果你是上傳軟件或者傳送數(shù)據(jù)大于90秒的時
- asp FSO 讀寫文件本文件實(shí)現(xiàn)代碼
- asp中isNull、isEmpty和空字符串的區(qū)別
- asp獲取用戶真實(shí)IP地址的方法
- asp連接sqlserver數(shù)據(jù)庫實(shí)現(xiàn)代碼
- asp中正則表達(dá)式過濾html代碼函數(shù)
- asp中g(shù)et post提交表單區(qū)別
- 網(wǎng)頁模板:ASP內(nèi)建對象Request
- xmlhttp的open方法使用詳解
- ASP的常用的自定義函數(shù)大全
- asp中用for循環(huán)的一個小技巧
- eWebEditor v3.8 列目錄
- ASP無組件分頁實(shí)現(xiàn)思路及代碼
- 相關(guān)鏈接:
- 教程說明:
ASP教程-ASP快速開發(fā)方法之?dāng)?shù)據(jù)操作
。