ASP 游標(biāo)參數(shù)詳解(ASP記錄集)第2/2頁
更新時間:2008年11月03日 17:43:55 作者:
經(jīng)常使用游標(biāo),但一些具體的說明不是很清楚,書上的東西太乏味
給你個比較有代表性的程序吧,估計能有所幫助
<%@ LANGUAGE = VBScript%>
<%
'------------------------------------------
'昨天晚上編的簡單數(shù)據(jù)庫(ACECESS,有id、password、
'register3個字段)操作,僅支持單表單條件操作,
'不過好像沒什么用:)
'col:待查詢字段名(必添)
'colvalue:待更新、添加字段的值(沒有用""代替)
'table:表名(必添)
'keyid:查詢條件的字段名(沒有用""代替,可選)
'keyvalue:查詢條件字段的值(沒有用""代替,可選)
'col和colvalue必須成對出現(xiàn)
'keyid和keyvalue必須同時出現(xiàn)
'------------------------------------------
%>
<%
Function DB_execute(col,colvalue,table,keyid,keyvalue,bz)
Dim ConnStr,conn,rs,sql
ConnStr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&Server.MapPath("data/game.mdb")
Set conn = Server.CreateObject("ADODB.Connection")
conn.open ConnStr
set rs=server.createobject("adodb.recordset")
for i=0 to UBound(col) step 1
if UBound(col)<>i then
sql=sql&col(i)&", "
else
sql=sql&col(i)&" "
end if
next
if keyid <> "" then
sql="select "&sql&"from "&table&" where "&keyid&"='"&keyvalue&"'"
else
sql="select "&sql&"from "&table
end if
select case bz
case "o"
rs.open sql,conn,1,1
dim rsnum
rsnum=rs.RecordCount
if rsnum > 0 then
dim rsArray()
redim rsArray(rsnum,UBound(col))
for i=0 to UBound(col) step 1
rsArray(0,i)=col(i)
next
for i=1 to rsnum step 1
for j=0 to UBound(col) step 1
rsArray(i,j)=rs(col(j))
next
next
DB_execute=rsArray
else
DB_execute="沒有查到任何數(shù)據(jù)"
end if
rs.close
set rs=nothing
case "u"
rs.open sql,conn,3,3
if rs.RecordCount > 0 then
for i=0 to UBound(col) step 1
rs(col(i))=colvalue(i)
next
rs.update
else
DB_execute="沒有查到這條數(shù)據(jù)"
end if
rs.close
set rs=nothing
case "i"
rs.open sql,conn,3,3
rs.addnew
for i=0 to UBound(col) step 1
rs(col(i))=colvalue(i)
next
rs.update
DB_execute="添加數(shù)據(jù)成功"
rs.close
set rs=nothing
case "d"
sql="delete from "&table&" where "&keyid&"='"&keyvalue&"'"
conn.Execute sql
DB_execute="刪除數(shù)據(jù)成功"
end select
conn.close
set conn=nothing
end Function
%>
<%
'返回記錄集
'temp=DB_execute(Array("id","password","register"),"","users","","","o")
'response.write temp(1,2)
'添加一條記錄
'temp=DB_execute(Array("id","password","register"),Array("test","test","0"),"users","","","i")
'response.write temp
'更新一條記錄
'temp=DB_execute(Array("id","password","register"),Array("new","new","1"),"users","id","test","u")
'response.write temp
'刪除一條記錄
'temp=DB_execute(Array("id","password","register"),"","users","id","new1","d")
'response.write temp
%>
相關(guān)文章
asp自動補全html標(biāo)簽自動閉合(正則表達式)
asp自動補全html標(biāo)簽自動閉合,方便asp截取帶有html標(biāo)簽的內(nèi)容,防止頁面變形2012-10-10ASP 遞歸調(diào)用 已知節(jié)點查找根節(jié)點的函數(shù)
已知節(jié)點查找根節(jié)點的asp函數(shù)2009-12-12ASP中解決“對象關(guān)閉時,不允許操作?!钡脑幃悊栴}……
本文解決ASP中“對象關(guān)閉時,不允許操作。”的詭異問題,找到問題的根本,才能真正意義上解決,供大家參考了。2016-03-03在ASP中不用模板生成HTML靜態(tài)頁直接生成.html頁面
有沒有辦法不用模板,如一個正常的htmer.asp頁面,直接生成為htmer.html頁面呢?當(dāng)然是可以的,而且非常簡單,今天就教大家在ASP中不用模板生成HTML靜態(tài)頁的方法2014-09-09ASP:ActiveX不能創(chuàng)建Scripting.FileSystemObject對象解決辦法
關(guān)于ActiveX不能創(chuàng)建Scripting.FileSystemObject對象的類似問題,大體上解決辦法都是類似的,主要是思想要清晰:首先考慮組件注冊問題,其次是組件權(quán)限問題,如果服務(wù)器配置沒有問題的話,那就仔細檢查一下你的程序源碼吧2011-11-11asp下用replace非正則實現(xiàn)代碼運行功能的代碼
asp下用replace非正則實現(xiàn)代碼運行功能的代碼...2007-09-09