全选---删除,为什么删除不掉呢?

sayfree 2008-02-29 10:33:16

<%
后台登录验证代码略
是一个新闻题目的列表。
chkid是题目列表前面的复选按钮chekboax.

%>
<%
dim idlist,idarr,nid
if isempty(trim(request("chkid"))) then '如果没有选择内容
response.write "<SCRIPT language=JavaScript>alert('您没有选择删除项!');"
response.write"this.history.back(-1);></SCRIPT>"
response.end
else
idlist=trim(request("chkid"))
if instr(idlist,",")>0 then
idarr=split(idlist)
for i = 0 to ubound(idarr)
nid=cstr(idarr(i))
call deleteannounce(nid) 'deleteannounce()为删除函数
next
else
call deleteannounce(cstr(idlist))
end if
end if
%>
<%
response.write "<SCRIPT language=JavaScript>alert('删除成功!');"
response.write"this.location.href='notice_list.asp';</SCRIPT>"
response.end
%>
<%
rs.close
set rs=nothing
%>
<%
sub deleteannounce(did)
dim rs,sql
set rs=server.createobject("adodb.recordset")
sql="delete from notice where n_id="&cstr(did)
conn.execute sql
if err.Number<>0 then
err.clear
response.write "删 除 失 败 !<br>"
end if
End sub
%>
...全文
202 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
直接用for in
不要再用split函数了!
  • 打赏
  • 举报
回复
看错了,应该是改这部分

idlist=trim(request("chkid"))
if idlist<>"" then
for id in idlist
call deleteannounce(id) 'deleteannounce()为删除函数
next
else
call deleteannounce(cstr(idlist))
end if
  • 打赏
  • 举报
回复
sub deleteannounce(did)
dim rs,sql
for id in did
sql="delete from notice where n_id="&cstr(id)
conn.execute sql
next
if err.Number <> 0 then
err.clear
response.write "删 除 失 败 ! <br> "
end if
End sub


记得你全选的是一个数组,你要循环才可以!
CoffeeShop 2008-02-29
  • 打赏
  • 举报
回复
Split(expression[, delimiter[, count[, start]]])
Split 函数的语法有以下参数:

参数 描述
expression 必选。字符串表达式,包含子字符串和分隔符。如果 expression 为零长度字符串,Split 返回空数组,即不包含元素和数据的数组。
delimiter 可选。用于标识子字符串界限的字符。如果省略,使用空格 ("") 作为分隔符。如果 delimiter 为零长度字符串,则返回包含整个 expression 字符串的单元素数组。
count 可选。被返回的子字符串数目,-1 指示返回所有子字符串。
compare 可选。指示在计算子字符串时使用的比较类型的数值。有关数值,请参阅“设置”部分

CoffeeShop 2008-02-29
  • 打赏
  • 举报
回复

idarr=split(idlist)
'应该改为
idarr=split(idlist,",")


若白师妹 2008-02-29
  • 打赏
  • 举报
回复
sql="delete from notice where n_id="&cstr(did)


把这条sql response.write出来看
sayfree 2008-02-29
  • 打赏
  • 举报
回复
问题是,提交表单后,虽然提示了“删除成功”,但是内容却没有删除。。
高手们给指点指点哪。
md5e 2008-02-29
  • 打赏
  • 举报
回复
idlist=trim(request("chkid"))

你用Response.write("idlist="& idlist)看一下有值吗
md5e 2008-02-29
  • 打赏
  • 举报
回复
HTM的代码是什么?
估计是那的问题
wnguh 2008-02-29
  • 打赏
  • 举报
回复
sql="delete from notice where n_id in ("&idarr&")"

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧