asp+sql怎么用复选框批量删除
asp文件1列出user表全部用户,并在用户旁加checkbox~checkbox的name设成一样,value为user表username字段,这个文件运行正常~选几个...
asp文件1列出user表全部用户,并在用户旁加checkbox~checkbox的name设成一样,value为user表username字段,这个文件运行正常~选几个复选框,按删除按钮提交表单到userdelete.asp没有报错,但是数据库并没有更改,用户未删除~~看了网上各种例子都不行~希望大虾帮我看看源代码,谢谢了!
asp文件1:(主要部分)
<%
Set conn=Server.CreateObject("ADODB.Connection")
set ad=Server.CreateObject("ADODB.Recordset")
conn.Open"provider=SQLOLEDB;data source=HKZJZ-24J9L3Q7M\FOR973;initial catalog=for973;user id=sa;Password=sa"
sql="select * from users"
ad.open sql,conn,1,3
while not ad.eof
username=ad.fields("username").value
password=ad.fields("password").value
if ad.fields("manager").value=1 then
m="管理员"
else
m="普通用户"
end if
%>
<tr>
<td><%=username%></td>
<td><%=password%></td>
<td><%=m%></td>
<td><input type=checkbox name=chk value="<%=ad("username")%>"></input>
</tr>
<%
ad.MoveNext
wend
ad.close
set ad=nothing
conn.close
set conn=nothing
%>
</table>
</body>
</html>
userdelete.asp:
<%
Dim chk,conn,ad
ID=request.form("chk")
Set conn=Server.CreateObject("ADODB.Connection")
conn.Open"provider=SQLOLEDB;data source=HKZJZ-24J9L3Q7M\FOR973;initial catalog=for973;user id=sa;Password=sa"
ID=Split(ID,",")
For Each aa in ID
If Trim(aa)<>"" Then
response.write(aa)
Sql="Delete From users Where username='"+aa+"'"
conn.execute sql
end if
Next
conn.close
%> 展开
asp文件1:(主要部分)
<%
Set conn=Server.CreateObject("ADODB.Connection")
set ad=Server.CreateObject("ADODB.Recordset")
conn.Open"provider=SQLOLEDB;data source=HKZJZ-24J9L3Q7M\FOR973;initial catalog=for973;user id=sa;Password=sa"
sql="select * from users"
ad.open sql,conn,1,3
while not ad.eof
username=ad.fields("username").value
password=ad.fields("password").value
if ad.fields("manager").value=1 then
m="管理员"
else
m="普通用户"
end if
%>
<tr>
<td><%=username%></td>
<td><%=password%></td>
<td><%=m%></td>
<td><input type=checkbox name=chk value="<%=ad("username")%>"></input>
</tr>
<%
ad.MoveNext
wend
ad.close
set ad=nothing
conn.close
set conn=nothing
%>
</table>
</body>
</html>
userdelete.asp:
<%
Dim chk,conn,ad
ID=request.form("chk")
Set conn=Server.CreateObject("ADODB.Connection")
conn.Open"provider=SQLOLEDB;data source=HKZJZ-24J9L3Q7M\FOR973;initial catalog=for973;user id=sa;Password=sa"
ID=Split(ID,",")
For Each aa in ID
If Trim(aa)<>"" Then
response.write(aa)
Sql="Delete From users Where username='"+aa+"'"
conn.execute sql
end if
Next
conn.close
%> 展开
1个回答
展开全部
给你个例子:
<%dim selectm,selectkey,selectbookid
selectkey=trim(request(trim("selectkey")))
selectm=trim(request("selectm"))
if selectkey="" then
selectkey=request.QueryString("selectkey")
end if
if selectkey="请输入关键字" then
selectkey=""
end if
'//删除商品
if selectm="" then
selectm=request.QueryString("selectm")
end if
selectbookid=request("selectbookid")
if selectbookid<>"" then
conn.execute "delete from wq_books where bookid in ("&selectbookid&")"
response.Redirect "managebook.asp"
response.End
end if
%>
<form name="form1" method="post" action="">
............
<input name="selectbookid" type="checkbox" id="selectbookid" value="<%=rs("bookid")%>">
全选
<input type="checkbox" name="checkbox" value="Check All" onClick="mm()">
<input type="submit" class=button name="Submit" value=" 删 除 " onClick="return test();">
<script>
function test()
{
if(!confirm('确认删除吗?')) return false;
}
</script>
<script language=javascript>
function mm()
{
var a = document.getElementsByTagName("input");
if(a[0].checked==true){
for (var i=0; i<a.length; i++)
if (a[i].type == "checkbox") a[i].checked = false;
}
else
{
for (var i=0; i<a.length; i++)
if (a[i].type == "checkbox") a[i].checked = true;
}
}
</script>
关键是在sql中使用 in
<%dim selectm,selectkey,selectbookid
selectkey=trim(request(trim("selectkey")))
selectm=trim(request("selectm"))
if selectkey="" then
selectkey=request.QueryString("selectkey")
end if
if selectkey="请输入关键字" then
selectkey=""
end if
'//删除商品
if selectm="" then
selectm=request.QueryString("selectm")
end if
selectbookid=request("selectbookid")
if selectbookid<>"" then
conn.execute "delete from wq_books where bookid in ("&selectbookid&")"
response.Redirect "managebook.asp"
response.End
end if
%>
<form name="form1" method="post" action="">
............
<input name="selectbookid" type="checkbox" id="selectbookid" value="<%=rs("bookid")%>">
全选
<input type="checkbox" name="checkbox" value="Check All" onClick="mm()">
<input type="submit" class=button name="Submit" value=" 删 除 " onClick="return test();">
<script>
function test()
{
if(!confirm('确认删除吗?')) return false;
}
</script>
<script language=javascript>
function mm()
{
var a = document.getElementsByTagName("input");
if(a[0].checked==true){
for (var i=0; i<a.length; i++)
if (a[i].type == "checkbox") a[i].checked = false;
}
else
{
for (var i=0; i<a.length; i++)
if (a[i].type == "checkbox") a[i].checked = true;
}
}
</script>
关键是在sql中使用 in
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询