asp中如何删除checkbox选中的数据问题
我的代码是这样的:<body><formname="add"method="post"action="add.asp"><inputtype="submit"name="...
我的代码是这样的:
<body>
<form name="add" method="post" action="add.asp">
<input type="submit" name="add" value="添加" style="font-family: Verdana; font-size: 8pt; color: #333333; border: 1 solid #000000">
</form>
<form name="del" method="post" action="del_submit.asp">
<input type="submit" name="del" value="删除所选" style="font-family: Verdana; font-size: 8pt; color: #333333; border: 1 solid #000000">
</form>
<font face="Verdana" size="2" >
<%
dim con,constr,rs
constr="Provider=microsoft.jet.oledb.4.0;data source=" &server.mappath ("db_contact.mdb")
set con=server.CreateObject("adodb.connection")
con.connectionstring=constr
con.open
set rs=server.CreateObject("adodb.recordset")
rs.open "select * from contact order by id asc",con
if rs.eof and rs.bof then
response.Write "<script>alert('No Record!');</script>"
end if
response.write "<table border=1>"
response.write "<tr><td>编号</td><td>姓名</td><td>手机</td><td>家庭电话</td><td>工作电话</td><td>地址</td><td>类别</td></tr>"
t=1
do while not rs.eof
If Instr(t/2, ".") = 0 Then
Color = "#FFFFFF"
ELse
Color = "#F0F0F0"
End If
response.Write "<tr><td>"& rs("id")&"</td><td>" & rs("name") & "</td><td>" & rs("mobile_phone") & "</td><td>" & rs("home_phone") & "</td><td>" & rs("work_phone") & "</td><td>" & rs("address") & "</td><td>" & rs("catagory") & "</td>"
%>
<td width="2%" bgcolor="<%= Color %>">
<input type="checkbox" name="id" value="<%= rs("ID") %>">
</td></tr>
<%
rs.movenext
t=t+1
loop
response.write "</table>"
If Request.Querystring("status") = "ok" Then
Response.Write "Selected records have been deleted."
End If
'rs.close
'set rs=nothing
'con.close
'set con=nothing
%>
</font>
</body>
================================================================
del_submit.asp代码:
<body>
<%
dim con,constr,rs
constr="Provider=microsoft.jet.oledb.4.0;data source=" &server.mappath ("db_contact.mdb")
set con=server.CreateObject("adodb.connection")
con.connectionstring=constr
con.open
For Each record In request("id")
SQLstmt = "delete * FROM contact WHERE ID=" & record
Con.Execute SQLStmt
'Con.Execute "delete * from contact where id=" & record
next
Response.Redirect "contact.asp?status=ok"
%>
</body>
但不知为何选中了checkbox,可就是删除不了记录,也不报错 展开
<body>
<form name="add" method="post" action="add.asp">
<input type="submit" name="add" value="添加" style="font-family: Verdana; font-size: 8pt; color: #333333; border: 1 solid #000000">
</form>
<form name="del" method="post" action="del_submit.asp">
<input type="submit" name="del" value="删除所选" style="font-family: Verdana; font-size: 8pt; color: #333333; border: 1 solid #000000">
</form>
<font face="Verdana" size="2" >
<%
dim con,constr,rs
constr="Provider=microsoft.jet.oledb.4.0;data source=" &server.mappath ("db_contact.mdb")
set con=server.CreateObject("adodb.connection")
con.connectionstring=constr
con.open
set rs=server.CreateObject("adodb.recordset")
rs.open "select * from contact order by id asc",con
if rs.eof and rs.bof then
response.Write "<script>alert('No Record!');</script>"
end if
response.write "<table border=1>"
response.write "<tr><td>编号</td><td>姓名</td><td>手机</td><td>家庭电话</td><td>工作电话</td><td>地址</td><td>类别</td></tr>"
t=1
do while not rs.eof
If Instr(t/2, ".") = 0 Then
Color = "#FFFFFF"
ELse
Color = "#F0F0F0"
End If
response.Write "<tr><td>"& rs("id")&"</td><td>" & rs("name") & "</td><td>" & rs("mobile_phone") & "</td><td>" & rs("home_phone") & "</td><td>" & rs("work_phone") & "</td><td>" & rs("address") & "</td><td>" & rs("catagory") & "</td>"
%>
<td width="2%" bgcolor="<%= Color %>">
<input type="checkbox" name="id" value="<%= rs("ID") %>">
</td></tr>
<%
rs.movenext
t=t+1
loop
response.write "</table>"
If Request.Querystring("status") = "ok" Then
Response.Write "Selected records have been deleted."
End If
'rs.close
'set rs=nothing
'con.close
'set con=nothing
%>
</font>
</body>
================================================================
del_submit.asp代码:
<body>
<%
dim con,constr,rs
constr="Provider=microsoft.jet.oledb.4.0;data source=" &server.mappath ("db_contact.mdb")
set con=server.CreateObject("adodb.connection")
con.connectionstring=constr
con.open
For Each record In request("id")
SQLstmt = "delete * FROM contact WHERE ID=" & record
Con.Execute SQLStmt
'Con.Execute "delete * from contact where id=" & record
next
Response.Redirect "contact.asp?status=ok"
%>
</body>
但不知为何选中了checkbox,可就是删除不了记录,也不报错 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询