永发信息网

asp我该如何删除数据库中满足条件的记录

答案:6  悬赏:10  手机版
解决时间 2021-03-23 17:56
比如这个删除的asp页面为del.asp
我目前是使用的这个代码
id = request.querystring("id")
sql = "delete from tel where id=" & id
Conn.Execute sql
可以删除这条记录,不过我现在想换一种方式,当数据和数据库匹配时才能删除,看我的具体说明:

在同一条记录中有id和name两个字段,id是自动编号且唯一的,name也是固定的字符,id和name都事先在前一个页面获得并通过参数的方式传递到这个删除页面,比如当别人访问del.asp?id=*&name=*这个页面时传递的id和name与数据库中记录的id和name匹配的时候才能删除,否则弹出提示。请问这段asp该怎么写。
最佳答案
<% id = request.querystring("id")
name1 = request.querystring("name")
sql = "select * from [tel] where id=" & id & " name='" & name & "'"
rs.open sql,conn,3,2
if not rs.eof then
rs.delete
rs.update
rs.close
else %>
<script language="vbscript">
msgbox "错误信息"
</script>
<%
end if %>
全部回答
具体的代码: id = request.querystring("id") name = request.querystring("name") '--------查询是否匹配--------- sqla="Select * from tel where id=" & id &" and name='"&name&"'" set rs=conn.execute(sqla) if rs.eof and rs.bof then Response.Write"弹出提示" '不匹配提示 else sql = "delete from tel where id=" & id '匹配执行 Conn.Execute sql end if rs.close set rs=nothing
全部代码如下~!!<br>&lt;%<br>dim id,name,Rs<br>id = request.querystring(&quot;id&quot;)<br>name = request.querystring(&quot;name&quot;)<br>sql = &quot;select * from tel where id=&quot; &amp; id &amp;&quot; and name='&quot;&amp;name&amp;&quot;'&quot;<br>set Rs=Conn.Execute sql<br>if Rs.Eof and Rs.Bof then<br>%&gt;<br>&lt;script type=&quot;text/javascript&quot;&gt;alert(&quot;对不起!数据库中无此记录,请确认输入!&quot;);&lt;/script&gt;<br>&lt;%else<br>sql = &quot;delete from tel where id=&quot; &amp; id &amp;&quot; and name=&quot;&amp;name<br>Conn.Execute sql <br>%&gt;
真正无错的代码:<br><br>&lt;%<br>id=trim(request(&quot;id&quot;))<br>names=trim(request(&quot;name&quot;))<br>if id&lt;&gt;&quot;&quot; and names&lt;&gt;&quot;&quot; then<br>sql=&quot;select * from tel where id=&quot;&amp; id &amp;&quot; name='&quot;&amp; names &amp;&quot;'&quot;<br>set rs=server.createobject(&quot;adodb.recordset&quot;)<br>  rs.open sql,conn,1,3<br>  if rs.eof or rs.bof then<br>     response.write &quot;&lt;script&gt;alert('记录不存在!');javascript:history.go(-1);&lt;/script&gt;&quot;<br>  else<br>     rs.delete<br>     rs.update<br>  end if <br>rs.close<br>set rs=nothing<br>else<br>response.write &quot;&lt;script&gt;alert('参数不足!');javascript:history.go(-1);&lt;/script&gt;&quot;<br>end if<br>%&gt; <br><br>另外提醒一下楼上几位,不知道就别来混分,欺骗别人感情!<br>记录集都没有定义怎么删除记录?鄙视一下~
&lt;%<br>id=trim(request(&quot;id&quot;))<br>name=trim(request(&quot;name&quot;))<br>sql=&quot;select * from tel where id=&quot;&amp; clng(id) &amp;&quot; name=&quot;&amp; names<br>set rs=server.createobject(&quot;adodb.recordset&quot;)<br>  rs.open sql,conn,1,3<br>  if rs.eof and rs.bof then<br>     response.write &quot;&lt;script&gt;alert('没有找到匹配的数据记录!');&lt;/script&gt;&quot;<br>  else<br>     rs.delete<br>     rs.update<br>  end if <br>rs.close<br>set rs=nothing<br>%&gt; <br>这个应该没问题<br>记得给分,若还有问题何以Hi我。
del.asp?id=*&amp;name=*<br><br>id = request.querystring(&quot;id&quot;)<br>name1=request.querystring(&quot;name&quot;)<br>set rs=server.createobject(&quot;adodb.recordset&quot;)<br>sql=&quot;select * from tel where id=&quot;&amp;id&amp;&quot; and name='&quot;&amp;name1&amp;&quot;'&quot;<br>rs.open sql,conn,3,3<br>if not rs.eof then<br>  rs.detele<br>  rs.update<br>  rs.close<br>  set rs=nothing<br>else<br> response.write&quot;&lt;script&gt;alert('您无法删除数据库中的资料!');history.go(-1)&lt;/script&gt;&quot;<br>end if
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
从乳山到威海多长时间,威海到荣成的发车时间
怎么看无线上网卡的好坏呀。。太多了怎么区分
最近买了一快PRW-6100,听说这指针表都可能出
你个女的很愿意和你聊天,让你给她唱歌,她也
东来顺北京新源里店这个地址在什么地方,我要
单选题“三鹿奶粉事件”发生以后,相关部门对
想去中华会计网校听课,但是有几种班级,我不
有拜的成语是什么
一切都是梦 用英语怎么说
本田哪一款车性能好,噪音没有那么大
判断题癌细胞是由正常细胞变化来的.
恒辉人力资源有限公司地址在什么地方,想过去
喜欢松的盆友谈一下这几种松如何区别.
为什么我手机话费用的很快?
如图,圆弧形桥拱的跨度AB=12米,拱高CD=4
推荐资讯
商店开分店可以用一个营业执照吗
150Ml水大概是多少?
单选题以下实验或操作不能达到目的的是A.用铜
基金定投是去银行的柜台办理吗?要怎么说?要
怀化市民族职业学校(东北门)地址在哪,我要去
如何在Word2007添加快速访问工具栏
单选题下列变化中分子本身发生了变化的是A.氨
卖自己唱吧郡公等级五颗钻
拒绝奢侈,提倡光盘行动高二800字议论文
若要提高多级放大电路的输入电阻,可以在第一
请问饭店用的小火电煮锅哪里有售?我准备开个
京ad8888劳斯莱斯幻影在现实中是谁的车
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?