Two methods for batch data deletion in ASP-application techniques

Source: Internet
Author: User
Method One:
Copy Code code as follows:

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)
If not rs.eof then
Delete_file (RS ("fname"))
End If
Rs.close
Set rs=nothing
Sql= "Delete from Jiang_fname where id=" &id (i)
Conn.execute SQL,SHU1
Shu=shu+1
Next

If Shu>0 Then
Response. Write ("<script>alert (' delete success '); location.href= '" &url& "';</script>")
Else
Response.Write (' <script>alert (' delete failed '); Javascript:history.back ();</script> ")
End If
Conn.close
Set conn=nothing



Method Two: Use in the keyword to realize the batch deletion of the data skillfully
Managenews.asp
Copy Code code as follows:

<!--#include file= "conn.asp"-->
<% ' Database connection file I'm not going to say much more.%> <title> Management News </title>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<link rel= "stylesheet" href= ". /index/style.css "type=" Text/css ">
<script>
Function del ()//used to determine whether a record has been selected
{
var flag=true;
var temp= "";
var tmp;
if ((document.form1.answer.length+ "") = = "undefined") {tmp=1}else{tmp=document.form1.answer.length}
if (tmp==1) {
if (document.form1.answer.checked) {
Flag=false;
Temp=document.form1.answer.value
}
}else{
for (i=0;i<document.form1.answer.length;i++) {
if (document.form1.answer[i].checked) {
if (temp== "") {
Flag=false;
Temp=document.form1.answer[i].value
}else{
Flag=false;
Temp = temp + "," + document.form1.answer[i].value
}
}
}
}
if (flag) {alert ("Sorry, you have no choice!") ")}
else{Name=document.form1.name.value
Alert (name)
if (confirm) (Are you sure you want to delete?) ")){
Window.location= "delnews.asp?id=" + temp;
}
}
return!flag;
}
</script>
<body>
<script language=javascript>
function Checkall (all)//functions for judging all selected records
{
var a = Document.getelementsbyname ("answer");
for (var i=0; i<a.length; i++) a[i].checked = all.checked;
}
</script>
<%
Set Rs=server.createobject ("Adodb.recordset")
Sql= "SELECT * FROM News ORDER BY addtime Desc"
Rs.Open sql,conn,1,3%>
<% if Rs.eof then%>
<table width= "50%" border= "0" align= "center" id= "Table2" >
<tr>
&LT;TD align= "center" >
No news!
</tr>
</table>
<% Else%>
<form method= "POST" Id=form1 name=form1>
<table width= "90%" border= "0" align= "center" class= "Tabdocborder" id= "Table3" >
<tr>
<td>
<table width= "80%" align= "center" id=tabdocmain border= ' 1 ' cellspacing= ' 0 ' cellpadding= ' 0 ' bordercolorlight= ' 82B4DD ' bordercolor= ' #b6d3eb ' class= "Tabdocmain" >
<thead>
<tr>
&LT;TD colspan= "7" align= "Center" >
News Management Center
</td>
</tr>
</thead>
<tbody>
<tr>
&LT;TD align=center>
Delete Box
</td>
&LT;TD align=center>
News Headlines
</td>
&LT;TD align=center>
Publish Time
</td>
&LT;TD align=center>
Management
</td>
</tr>
<%
Do as not rs.eof
%>

<tr>
&LT;TD align=center><input type= "checkbox" name= "Answer" value= "<%=rs" ("id")%> "id=" Checkbox1 ">
</td>
&LT;TD align=left><%if Len (rs ("title")) <=30 Then%><%=rs ("title")%><%else%>
<%= (Left (RS ("title"),)%&gt ....
<%end if%></td>
&LT;TD align=left><%=rs ("Addtime")%></td>
&LT;TD align=center><a href= "editnews.asp?id=<%=rs (" id ")%>" > Edit </a></td>
</tr>
</tbody>
<%
Rs.movenext
Loop
%>

<tr>
&LT;TD colspan= "7" align= "Center" >
<input type= "checkbox" Name= "Chkall" value= "on" onclick= "Checkall (This)" id= "Checkbox2" > select all Display News
<input type= "button" Name= "Btndelete" value= "delete" Style= ' font-family: Song body; Font-size:9pt ' onclick= ' del () "id=" Button1 ">
</td>
</tr>
</table>
</form>
</td>
</tr>
<%end if%>
</table>
<% Set rs=nothing
Conn.close
Set conn=nothing
%>
</body>

delnews.asp file
Copy Code code as follows:

<!--#include file= "conn.asp"-->
<%
arrdel=request ("id")
' Response.Write arrdel
sql= ' DELETE from news where ID in (' &arrdel& ') '
' Response.Write SQL
conn. Execute SQL
Set conn=nothing
Response.Write "<script language=javascript>alert (' Delete succeeded! ');"
Response.Write "Javascript:history.go ( -1) </SCRIPT>"
Response.End
%>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.