欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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)文章

最新評論