ASP快速開發方法之數據操作(3)_ASP教程

      編輯Tag賺U幣
      教程Tag:暫無Tag,歡迎添加,賺取U幣!

      推薦:ASP實例:即時顯示當前頁面瀏覽人數
      ASP實現即時顯示當前頁面瀏覽人數 online.asp文件 以下為引用的內容: <!--#include file="dbconn.asp" --> <% onlineTimeout=10

      呵呵,這樣,我們只要用兩句語句就完成了數據的讀取。同樣的,通過在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 DataTable
      Num=loadData.SelectDataNum(sql)
      %>

      來取得記錄條數,可以用于分頁或者用戶名是否重復的判斷。

      其它的對數據記錄的操作我們新建一個類,使用UpdateTable來完成操作:

      以下為引用的內容:
      <%
      Class DataTable
      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 DataTable
      UpdateDate.UpdataSql(sql)
      %>

      當然你也這以這樣寫:

      以下為引用的內容:
      <%
      sql="insert into cnarticle(cn_title,cn_author,cn_content) values(' "&whattitle&" ',' "&whoauthor&" ',' "&whatcontent&" ')"
      opendatabase
      conn.execute(sql)
      closedatabase
      %>

      考慮到可能刪除語句我們會這么寫:
      sql="delect from cnarticle where id in(1,3,5,6,7,8)"

      我新建一個類DeldataTable,直接使用DeldataTable.DeldataSql(tableName,DelField,id)完成記錄的刪除操作。

      以下為引用的內容:
      <%
      Class DataTable
      dim tempvalue
      public Function DeldataSql(tableName,DelField,id)
      If tableName<>"" and id<>"" then
      sql="delete from "&tableName
      If isnumeric(id) and instr(id,",")=0 then
      sql = sql & " where "&DelField&" = "&id
      Else
      sql = sql & " where "&DelField&" in ("& id &")"
      End If
      Opendatabase
      conn.execute(sql)
      Closedatabase
      tempvalue=true
      Else
      tempvalue=false
      End If
      DeldataSql=tempvalue
      End Function
      End Class
      %>

      分享:ASP教程:解決ASP腳本運行超時的方法
      最近在學習服務器知識。有時候遇到asp腳本運行超時的錯誤,真是麻煩。找了相關資料,其中有一些解決方法。 IIS默認的腳本超時時間是90秒 這樣的話如果你是上傳軟件或者傳送數據大于90秒的時

      來源:模板無憂//所屬分類:ASP教程/更新時間:2008-08-22
      相關ASP教程