关于批量删除问题!

joshua2005 2005-03-30 10:44:58
以下是部分代码,想实现根据CKBOX的选择,进行数据的删除。
(暂时无法实现,请帮忙看看,谢谢)
---------------------------
<%If Request.QueryString("action")="del" Then
Call userdel
Else
%>

<table width="500" border="1" cellpadding="0" cellspacing="0" align="center" class=TableBorder>
<tr height="22" valign="middle" align="center">
<th width="30" height="18">ID</th>
<th width="80">用户名</th>
<th width="81">密码</th>
<th width="105">权限</th>
<th width="127">操作</th>
<th width="88"><a href="main.asp">添加</a><br>
<a href="?action=del&id=<%=ll(0)%>" onclick="{if(confirm('确定删除吗?')){return true;}return false;}">删除</a></th>
</tr>

<%
Dim ll
Set ll = Conn.Execute("Select ID,name,password,quanx From yongh")
Do While Not ll.Eof
%>
<tr valign="middle" bgcolor="#FFFFFF" align="center" height="22">
<td width="30"><%=ll(0)%></td>
<td width="80"><a href="User_Edit.asp?id=<%=ll(0)%>" title="点击编辑"><%=ll(1)%></a></td>
<td width="81"><%=ll(2)%></td>
<td width="105"><%Select Case ll("quanx")
Case 1
Response.write("管理员")
Case 2
Response.write("总办")
Case 3
Response.write("工艺部")
Case 4
Response.write("设计部")
End Select%></td>
<td width="127"><a href="User_Edit.asp?id=<%=ll(0)%>">编辑</a> |
<input name="ckbox" type="checkbox" value=<%=ll("id")%>></td>
<td width="88"> </td>
</tr>
<%
ll.MoveNext
Loop
ll.Close
Conn.Close
Set ll=Nothing
Set Conn=Nothing
%>
</table>
</body>
<%End if%>
</html>

<%
Sub userdel
Dim id,dd
id = Request.QueryString("ckbox")
Set dd = Conn.Execute("Delete From yongh Where in ID = "&id)

Response.write "<script language='javascript'>alert('删除成功!');" & chr(13)
Response.write "window.document.location.href='admin_del.asp';</script>"
End Sub
%>
...全文
222 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
joshua2005 2005-03-30
  • 打赏
  • 举报
回复
问题还是没有解决啊,麻烦大家仔细看一下我的【乱】源代码。谢谢丫
daknis 2005-03-30
  • 打赏
  • 举报
回复
checkbox
joshua2005 2005-03-30
  • 打赏
  • 举报
回复
---已经修改了部分代码--主要以下四个部分
但是还是不能根据选择值进行数据删除?
1.
<%
If Request.QueryString("action")="del" Then
Call userdel
Else
%>

2.
<td><input name="ckbox" type="checkbox" value=<%=ll("id")%>></td>

3.
<a href="?action=del&id=<%=ll(0)%>" onclick="{if(confirm('确定删除吗?')){return true;}return false;}">删除</a></th>


4.
<%
Sub userdel
Dim id,dd
id = Request.QueryString("ckbox")
Set dd = Conn.Execute("Delete From yongh Where ID in "&id)
Response.write "<script language='javascript'>alert('删除成功!');" & chr(13)
Response.write "window.document.location.href='admin_del.asp';</script>"
End Sub
%>

jarraytan 2005-03-30
  • 打赏
  • 举报
回复
绝对可以批量。我保证。
jarraytan 2005-03-30
  • 打赏
  • 举报
回复
建议你先加个表单,比较方便点。

然后提交后,
ckbox=Trim(Request.Form("ckbox"))
提取选择的要删除的值,
再删除它:
"delete from tab where id in (" & ckbox &")"
baiyunfei 2005-03-30
  • 打赏
  • 举报
回复
Set dd = Conn.Execute("Delete From yongh Where ID in (" & replace(id," ","") & ")")
underone 2005-03-30
  • 打赏
  • 举报
回复
Delete From yongh Where ID in "&id&"
underone 2005-03-30
  • 打赏
  • 举报
回复
Delete From yongh Where in ID = "&id
没有等号
jarraytan 2005-03-30
  • 打赏
  • 举报
回复
代码太多了,看的头晕。。。。
iasky 2005-03-30
  • 打赏
  • 举报
回复
恩,不错,了解,谢谢fcuandy(www.webizs.com)

改进了
fcuandy 2005-03-30
  • 打赏
  • 举报
回复
楼上朋友, 把你的改改吧

Num=Request.Form("ContentID").Count
For i = 1 To Num
Conn.ExeCute("Delete From Content Where ContentID="&Request.Form("ContentID")(i))
Next

自己想想效率

ID=Request.Form("ContentID")
Conn.ExeCute("Delete From Content Where ContentID in (" & ID & ")")

难道这样就不能用?
iasky 2005-03-30
  • 打赏
  • 举报
回复
我的完整的例子


<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<% Option Explicit %>
<!--#include file="Inc/Class_DB.asp" -->
<%
Dim DBC,Conn
Set DBC = New DataBaseClass
Set Conn = DBC.OpenConnection()
Set DBC = Nothing

Dim Num,i
If Request.Form("Operation")="DEL" Then
Num=Request.Form("ContentID").Count
For i = 1 To Num
Conn.ExeCute("Delete From Content Where ContentID="&Request.Form("ContentID")(i))
Next
End If

Dim strPage
strPage=Request.QueryString("Page")
If strPage<=1 OR strPage="" then strPage=1
Dim RS,Sql
Set RS=Server.CreateObject("ADODB.RecordSet")
Sql="Select * From Content Order By ContentID Desc"
RS.Open Sql,Conn,1,1

Function GetClassName(ClassID)
Dim RsClass,SqlClass
Set RsClass=Server.CreateObject("ADODB.RecordSet")
SqlClass="Select ClassName From Class Where ClassID=" & ClassID
RsClass.Open SqlClass,Conn,1,1
If RsClass.EOF And RsClass.BOF Then
GetClassName = "<font color=""FF0000"">分类已删除</font>"
Else
GetClassName = RsClass(0)
End If
End Function
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>删除信息 -- 西物视频演示管理程序</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="css.css" rel="stylesheet" type="text/css">
<SCRIPT language=JavaScript src="Inc/Total.js"></SCRIPT>
</head>

<body>
<br><br>
<form name=form method=post action="">
<table width="85%" border="0" align="center" cellpadding="2" cellspacing="1" class="tableborder">
<tr>
<td height="20" colspan="4" class="header">删除信息</td>
</tr>
<tr height="20" class="header" align="center">
<td width="4%">ID</td>
<td>信息题目</td>
<td>分类</td>
<td width="6%">删除</td>
</tr>
<%
If RS.EOF And RS.BOF Then
%>
<tr>
<td height="20" colspan="4" class="category" align="center">暂时没有信息</td>
</tr>
<%
Else
Dim Select_Count,Select_PageCount
RS.PageSize=20
RS.AbsolutePage=cInt(strPage)
Select_Count=RS.RecordCount
Select_PageCount=RS.PageCount

For i=1 To RS.PageSize
If RS.EOF Then Exit For

%>
<tr height="20" class="category" align="center">
<td width="4%"><% = RS("ContentID") %></td>
<td><% = RS("Title") %></td>
<td><% = GetClassName(RS("ClassID")) %></td>
<td width="6%"><input Name="ContentID" type="checkbox" Value=<%=rs("ContentID")%>></td>
</tr>
<%
RS.MoveNext
Next
%>
<tr>
<td height="20" colspan="7" class="category" align="right">
<input type=hidden value=DEL name=operation>
<input name="chkall" type="checkbox" onclick="CheckAll(this.form)">
选中所有
<input type=submit value=删除 onclick="return Del()"></td>
</tr>
<tr>
<td height="20" colspan="7" class="category" align="center">
 共<b><% = Select_Count %></b>条记录,每页20条,本页是第<b><% = strPage %></b>页.
<%
If int(strPage)>1 then
response.Write" <a href=?page=1>第一页</a> "
response.Write" <a href=?page="&cstr(cint(strpage)-1)&">上一页</a> "
End if
If int(strPage)<Select_PageCount then
response.Write" <a href=?page="&cstr(cint(strpage)+1)&">下一页</a>"
response.Write" <a href=?page="& Select_PageCount &">最后一页</a> "
End if
%>
</td>
</tr>
<%
End If
RS.Close
Set RS = Nothing
%>

</table>
</form>
</body>
</html>
<%
Set Conn = Nothing
%>
joshua2005 2005-03-30
  • 打赏
  • 举报
回复
还是不行。
可不可以给我一个好的例子研究一下啊?
谢谢
iasky 2005-03-30
  • 打赏
  • 举报
回复
<input Name="ContentID" type="checkbox" Value=<%=rs("ContentID")%>>

Dim Num,i
If Request.Form("Operation")="DEL" Then
Num=Request.Form("ContentID").Count
For i = 1 To Num
Conn.ExeCute("Delete From Content Where ContentID="&Request.Form("ContentID")(i))
Next
End If
fcuandy 2005-03-30
  • 打赏
  • 举报
回复
Dim id
id = trim(Request("ckbox"))
Conn.Execute("Delete From yongh Where ID in (" & id & ")")
fengxq87 2005-03-30
  • 打赏
  • 举报
回复
先写一个JAVASCRIPT把已选的记录ID记下提交给删除记录的网页,
而删除记录的网页就把刚刚提交的ID一个个用Split函数拆开,
将它组织成以下型式语句执行就行了
"delete from tab where id = 记录ID or id=记录ID"

28,406

社区成员

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

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