亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

asp快速開發(fā)方法之數據操作實例代碼第2/3頁

 更新時間:2007年08月08日 11:05:52   作者:  

現在我們的showit.asp可以這樣寫:
showit.asp
<!--#include file="conn.asp" -->
<%
sql = "Select * from cnarticle"
opendatabase
rs.Open sql,conn,1,1
If not Rs.eof then
    Do Until rs.EOF
    response.write("文章標題是:"& rs("cn_title"))
    response.write("<br>文章作者是:"& rs("cn_author"))
    response.write("<br>文章加入時間是:"& rs("cn_time"))
    response.write("<br>文章內容是:"& rs("cn_content"))
    response.write("<hr>")
    rs.MoveNext
    Loop
else
    response.write ("暫時還沒有文章")
end if
Closedatabase
%>
嗯,我們又少寫了一些東西,這樣是最簡單的嗎?當然不是!還可以更簡單。
使用GetRows把查詢出來的數據傳給一個變量,使用ubound方法取得數據記錄條數。
不明白?沒關系,讓我們繼續(xù)往下看:

再建個文件:sql.asp
sql.asp
<%
Class selectDataTable
    public Function SelectData(sql)
        If sql<>"" then
            opendatabase
            Rs.open sql,conn,1,1
            If not Rs.eof then
                Thedata=Rs.GetRows(-1)
                Closedatabase
            Else
                Closedatabase
            End If
        End If
        SelectData=Thedata
    End Function
End Class
%>
嗯,復制它就可以了,現在我們的showit.asp可以簡單地這樣寫:

showit.asp
<!--#include file="conn.asp" -->
<!--#include file="sql.asp" -->
<%
sql = "Select * from cnarticle"
set loadData=new selectDataTable
Thedata=loadData.SelectData(sql)
If isarray(Thedata) then
    Num=ubound(Thedata,2)
    for i=0 to Num
        response.write("文章標題是:"& Thedata(1,i))
        response.write("<br>文章作者是:"& Thedata(2,i))
        response.write("<br>文章加入時間是:"& Thedata(3,i))
        response.write("<br>文章內容是:"& Thedata(4,i))
        response.write("<hr>")
    next
else
    response.write("暫時還沒有文章")
End If
%>
呵呵,這樣,我們只要用兩句語句就完成了數據的讀取。同樣的,通過在sql.asp中加入
<%
    public Function SelectDataNum(sql)
        If sql<>"" then
            Opendatabase
            Rs.open sql,conn,1,1
            If not Rs.eof then
                Thedata=Rs.GetRows(-1)
                Closedatabase
                Num=ubound(Thedata,2)
            Else
                Closedatabase
            End If
        End If
        SelectDataNum=Num
    End Function
%>
我們就可以使用
<%
sql = "Select * from cnarticle"
set loadData=new selectDataTable
Num=loadData.SelectDataNum(sql)
%>
來取得記錄條數,可以用于分頁或者用戶名是否重復的判斷。

其它的對數據記錄的操作我們新建一個類,使用UpdateTable來完成操作:
<%
Class UpdataTable
    public Function UpdataSql(sql)
        If sql<>"" then
            Opendatabase
            conn.execute(sql)
            Closedatabase
        End If
    End Function
End Class
%>
<%
sql = "delete from cnarticle"
set UpdateDate=new UpdataTable
UpdateDate.UpdataSql(sql)
%>

相關文章

最新評論