为什么rs.addnew 后数据写入的是两次?得到两条记录?

来源:百度知道 编辑:UC知道 时间:2024/05/31 07:50:15
代码如下
If n_title = "" or n_type = "" or n_lei = "" or NeiRong = "" Then
response.write"<script>alert('信息填写不完整');;history.go(-1);</script>"
response.end
else
If n_lei = 1 and n_img = "" Then
response.write"<script>alert('你选择了图片新闻,但是图片标题没填。');history.go(-1);</script>"
response.end
Else
set rs=server.createobject("adodb.recordset")
sql="select * from [news]"
rs.open sql,conn,1,3
rs.addnew
rs("n_title") = n_title
rs("n_type") = n_type
rs("n_lei") = n_lei
rs("n_img") = n_img

rs.update

rs.close
Set rs = NoThing
response.Write "<script language=JavaScript>{window.alert('新闻增加成功!');window.location.href='Admin_Newslist.asp';}</script>"
response.end

代码没问题,有一种可能,是不是提交的时间,鼠标按键有问题,会因为震动提交两次呢?这个网关程序也就执行了两次。
我的解决办法是为了防止重复提交,要对每次发布的页面分配一个ID号,用HIDDEN提交,然后一起写库,在写库时先查找这个ID是不是存在,如果不存在才ADDNEW并UPDATE,否则跳过这部,直接继续后边的程序,比如返回列表或是显示添加完成的信息。