读书人

asp怎么大批量更新数据

发布时间: 2012-02-12 17:16:34 作者: rapoo

asp如何大批量更新数据
本人的网站程序是用asp+sql2000做的
现在想做的是:输入点击数,然后提交.
在表Merchant_News中就完成所有的数据中的count字段就全部更新.
在数据库里面执行
 Update Merchant_News Set Count=Count+1
能成功.
但在程序里面.(要是直接看很难受的话,可以复制下来,放在DW里看,谢谢!)

<!--#include file= "../Conn.asp " -->
<!--#include file= "Inc/Session.asp " -->
<!--#include file= "../Inc/Char.asp " -->
<!--#include file= "Inc/priv.asp " -->
<html>
<head>
<title> <%=SysVer%> > > </title>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 ">
<link rel= "stylesheet " href= "css/Style.css " type= "text/css ">
</head>
<body topmargin= "0 " leftmargin= "0 ">

<%
Select Case Request( "Action ")

Case "SaveAdd "
Call SaveAdd()

End Select


Sub SaveAdd()
Dim typeid,hits,Rs,Sql,AreaName
Dim Result
typeid=Clng(Trim(Request( "typeid ")))
hits=Clng(Trim(Request( "hits ")))
'Set Rs=Server.CreateObject( "ADODB.RecordSet ")
if typeid=1 then
Set Rs=conn.execute( "Update Merchant_News Set Count=Count+ "&hits& " ")
' Sql= "Select count from merchant_news "
end if
if typeid=2 then
Set Rs=conn.execute( "UPDATE Corporation_News Set COUNT=Count+ "&hits& " ")
end if
if typeid=3 then
Set Rs=conn.execute( "Update User_News Set Count=Count+ "&hits& " ")
end if
'Rs.Open Sql,conn,1,3
'Rs( "Count ")=Rs( "Count ")+hits UPDATE User_News SET
'Rs.Update
Rs.Close
'Set Rs=Nothing

Result= "点数添加成功,系统将在2秒后回到首页 "
Call warn(Result, "Add_hits.asp ",1)
End Sub
%>
<table width= "100% " border= "0 " cellpadding= "3 " cellspacing= "1 " class= "border ">
<form name= "form1 " method= "post " action= "?Action=SaveAdd " onsubmit= "return checkAdd(this) ">
<tr align= "center " bgcolor= "#000000 ">
<td colspan= "2 " class= "topbg "> <font color= "#FFFFFF "> 增加点击数 </font> </td>
</tr>
<tr>
<td width= "20% " height= "23 " align= "right " class= "tdbg "> 选择:
</td>
<td width= "80% " class= "tdbg "> <select name= "typeid " size= "1 " id= "typeid ">
<option value= "0 "> 请选择 </option>


<option value= "1 "> 商家信息 </option>
<option value= "2 "> 企业信息 </option>
<option value= "3 "> 个人信息 </option>
</select>
会增加全体成员的点击数 </td>
</tr>
<tr>
<td height= "23 " align= "right " class= "tdbg "> 增加点数: </td>
<td height= "23 " class= "tdbg "> <input name= "hits " type= "text " id= "hits " size= "20 " maxlength= "20 "> </td>
</tr>
<tr>
<td height= "23 " align= "right " class= "tdbg ">   </td>
<td height= "23 " class= "tdbg "> <input name= "Submit " type= "submit " class= "button01-out " id= "LoginButton " value= "添 加 ">
<input name= "Submit2 " type= "reset " class= "button01-out " id= "Submit " value= "取 消 ">
<input name= "Submit32 " type= "button " class= "button01-out " value= "返 回 " onclick= "window.history.back(); "> </td>
</tr>
</form>
</table>
<script>
function checkAdd(obj){
if(obj.typeid.value== "0 "){
alert( "请正确的选择! ");
obj.typeid.focus();
return false;
}
if(obj.hits.value== " "){
alert( "请输入点数名称。 ");
obj.hits.focus();
return false;
}
return true;
}
</script>
</body>
</html>
提交时没有成功.

刚开始时用
Set Rs=Server.CreateObject( "ADODB.RecordSet ")
Sql= "Select count from merchant_news "
Rs.Open Sql,conn,1,3
Rs( "Count ")=Rs( "Count ")+hits
Rs.Update
能提交成功,但Count值没有变.

是不是它没有游标,不能一个一个的去更改.


[解决办法]
使用do while not rs.eof .... rs.movenext
[解决办法]
Set Rs=Server.CreateObject( "ADODB.RecordSet ")
Sql= "Select count from merchant_news "
Rs.Open Sql,conn,1,3
do while not rs.eof


Rs( "Count ")=Rs( "Count ")+hits
Rs.Update
rs.movenext
loop
rs.close
...

[解决办法]
do while not rs.eof
rs( "count ")=rs( "count ")+hits
rs.update
rs.movenext
loop
[解决办法]
第一种方法一般用于单条数据更新

批量更新的用do while 比较方便
[解决办法]
FSO权限问题关系到读写的问题 设置下就好了

网页中的FLASH动画无法显示一般是没有安装FLASH插件或被某软件拦截

客户端能不能显示与服务器一般没有多大关机

读书人网 >ASP

热点推荐