asp 刪除數(shù)據(jù)庫記錄的代碼
更新時(shí)間:2010年09月28日 22:07:46 作者:
asp刪除數(shù)據(jù)庫教程記錄其實(shí)在asp中是很非常容易做的事情了,只要連接數(shù)據(jù)庫了,再利用sql delete函數(shù)來刪除就ok了,下面來看看實(shí)例吧。
刪除單條記錄
id = saferequest("id")
sql="delete from table1 where whereid>"&id&""
rs.open sql,conn,1,3
response.write "<script>alert('刪除成功');location.href='del.asp';</script>"
set rs=nothing
set conn=nothing
這是過濾非法字符函數(shù)
function saferequest(paraname)
dim paravalue
paravalue=request(paraname)
if isnumeric(paravalue) = true then
saferequest=paravalue
exit function
elseif instr(lcase(paravalue),"select ") > 0 or instr(lcase(paravalue),"insert ") > 0 or instr(lcase(paravalue),"delete from") > 0 or instr(lcase(paravalue),"count(") > 0 or instr(lcase(paravalue),"drop table") > 0 or instr(lcase(paravalue),"update ") > 0 or instr(lcase(paravalue),"truncate ") > 0 or instr(lcase(paravalue),"asc(") > 0 or instr(lcase(paravalue),"mid(") > 0 or instr(lcase(paravalue),"char(") > 0 or instr(lcase(paravalue),"xp_cmdshell") > 0 or instr(lcase(paravalue),"exec master") > 0 or instr(lcase(paravalue),"net localgroup administrators") > 0 or instr(lcase(paravalue)," and ") > 0 or instr(lcase(paravalue),"net user") > 0 or instr(lcase(paravalue)," or ") > 0 or instr(lcase(paravalue),"""")>0 or instr(lcase(paravalue),"'")>0 then
response.write "請不要在函數(shù)中加入非法字符!"
response.end
else
saferequest=paravalue
end if
end function
批量刪除方法:
主要是利用for循環(huán)來實(shí)現(xiàn)。
id=request.form("checkbox")
id=Split(id,",")
shu=0
for i=0 to UBound(id)
sql="select * from jiang_fname where id="&id(i)
set rs=conn.execute(sql)
shu=shu+1
next
復(fù)制代碼 代碼如下:
id = saferequest("id")
sql="delete from table1 where whereid>"&id&""
rs.open sql,conn,1,3
response.write "<script>alert('刪除成功');location.href='del.asp';</script>"
set rs=nothing
set conn=nothing
這是過濾非法字符函數(shù)
復(fù)制代碼 代碼如下:
function saferequest(paraname)
dim paravalue
paravalue=request(paraname)
if isnumeric(paravalue) = true then
saferequest=paravalue
exit function
elseif instr(lcase(paravalue),"select ") > 0 or instr(lcase(paravalue),"insert ") > 0 or instr(lcase(paravalue),"delete from") > 0 or instr(lcase(paravalue),"count(") > 0 or instr(lcase(paravalue),"drop table") > 0 or instr(lcase(paravalue),"update ") > 0 or instr(lcase(paravalue),"truncate ") > 0 or instr(lcase(paravalue),"asc(") > 0 or instr(lcase(paravalue),"mid(") > 0 or instr(lcase(paravalue),"char(") > 0 or instr(lcase(paravalue),"xp_cmdshell") > 0 or instr(lcase(paravalue),"exec master") > 0 or instr(lcase(paravalue),"net localgroup administrators") > 0 or instr(lcase(paravalue)," and ") > 0 or instr(lcase(paravalue),"net user") > 0 or instr(lcase(paravalue)," or ") > 0 or instr(lcase(paravalue),"""")>0 or instr(lcase(paravalue),"'")>0 then
response.write "請不要在函數(shù)中加入非法字符!"
response.end
else
saferequest=paravalue
end if
end function
批量刪除方法:
主要是利用for循環(huán)來實(shí)現(xiàn)。
復(fù)制代碼 代碼如下:
id=request.form("checkbox")
id=Split(id,",")
shu=0
for i=0 to UBound(id)
sql="select * from jiang_fname where id="&id(i)
set rs=conn.execute(sql)
shu=shu+1
next
您可能感興趣的文章:
相關(guān)文章
ASP編程入門進(jìn)階(十八):FSO組件之文件操作(上)
ASP編程入門進(jìn)階(十八):FSO組件之文件操作(上)...2007-01-01ASP編程入門進(jìn)階(十八):FSO組件之文件操作(下)
ASP編程入門進(jìn)階(十八):FSO組件之文件操作(下)...2007-01-01查看所有的Server Variables的環(huán)境變量
查看所有的Server Variables的環(huán)境變量...2007-02-02javascript asp教程第七課--response屬性
javascript asp教程第七課--response屬性...2007-03-03127.0.0.1無法訪問,沒有權(quán)限: GetObject
127.0.0.1無法訪問,沒有權(quán)限: GetObject...2007-02-02asp中Request.ServerVariables的參數(shù)集合
這篇文章主要介紹了asp中Request.ServerVariables的參數(shù)集合,需要的朋友可以參考下2020-02-02