Use the in keyword to delete data in batches

Source: Internet
Author: User
Use the in keyword to delete data in batches
  Use the in keyword to delete data in batches
Original: Wang Zi
Batch deletion of data is often encountered in Web programming. We usually delete data in batches through loops. However, if a program module is recycled too much, the quality of the program module will decrease. Therefore, this article describes how to use the in keyword to batch delete data.
Let's use an example to explain how to batch delete data with the in keyword.
If we want to delete the data on this page: The related code is as follows:
Managenews. asp <! -- # Include file = "conn. asp" -->
<% 'I will not say much about the database connection file. %> <HTML>
<Head>
<Title> managing 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 the record has a selected Function
{
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 not selected it yet! ")}
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>
</Head>
<Body>
<Script language = JavaScript>
Function checkall (all) // function used to judge 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>
<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>
<TD colspan = "7" align = "center">
News Management Center
</TD>
</Tr>
</Thead>
<Tbody>
<Tr>
<TD align = center>
Delete box
</TD>
<TD align = center>
News Title
</TD>
<TD align = center>
Release Date
</TD>
<TD align = center>
Management
</TD>
</Tr>
<%
Do while not Rs. EOF
%>

<Tr>
<TD align = center> <input type = "checkbox" name = "Answer" value = "<% = RS (" ID ") %>" id = "checkbox1">
</TD>
<TD align = left> <% if Len (RS ("title") <= 30 then %> <% = RS ("title") %> <% else %>
<% = (Left (RS ("title"), 30) %>...
<% End if %> </TD>
<TD align = left> <% = RS ("addtime") %> </TD>
<TD align = center> <a href = "editnews. asp? Id = <% = RS ("ID") %> "> edit </a> </TD>
</Tr>
</Tbody>
<%
Rs. movenext
Loop
%>

<Tr>
<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:; 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>
</Html>
Delnews. asp file
<! -- # 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 ('deleted successfully! ');"
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.