推薦: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秒的時
新聞熱點(diǎn)
疑難解答
圖片精選