asp如何用ADO批量更新记录?
时间:2010-06-10 18:42:00
如何用ADO批量更新记录?
是的,ADO有这项功能,不过好像用的人不太多(不了解还是不会用呢?):
<HTML>
<HEAD>
<TITLE>ADO批量更新记录 - asp之家</TITLE>
</HEAD>
<BODY >
<%
Set cn = Server.CreateObject("ADODB.Connection")
Set rs = Server.CreateObject("ADODB.RecordSet")
cn.Open Application("guestDSN")
rs.ActiveConnection = cn
rs.CursorType = adOpenStatic
rs.LockType = adLockBatchOptimistic
rs.Source = "SELECT * FROM authors"
rs.Open
If (rs("au_fname") = "Liyanbing") or (rs("au_fname") = "Wuxiaotao") Then
newval = "Songyingte"
Else
newval = "Liyanbing"
End If
If err <> 0 Then
%>
<B>噢,记录集打开失败!</B>
<% Else %>
<B>恭喜,记录集打开成功!</B><P>
<% End If %>
<H2>在批量更新之前</H2>
<TABLE BORDER=1>
<TR>
<% For i = 0 To rs.Fields.Count - 1 %>
<TD><B><%= rs(i).Name %></B></TD>
<% Next %>
</TR>
<% For j = 1 To 5 %>
<TR>
<% For i = 0 To rs.Fields.Count - 1 %>
<TD><%= rs(i) %></TD>
<% Next %>
</TR>
<%
rs.MoveNext
Next
rs.MoveFirst
%>
</TABLE>
在表中随机移动并执行更新!<BR>
<%
Randomize
r1 = Int(rnd*3) + 1
' 累计n次
r2 = Int(rnd*2) + 1
' 在更新数据之间跳过n位
For i = 1 To r1
response.write "累计: " & i & "<BR>"
rs("au_fname") = newval
For j = 1 To r2
rs.MoveNext
response.write "移动下一个<BR>"
Next
Next
rs.UpdateBatch adAffectAll
rs.Requery
rs.MoveFirst
%>
<% rs.MoveFirst %>
<H2>在批量更新之后</H2>
<TABLE BORDER=1>
<TR>
<% For i = 0 To rs.Fields.Count - 1 %>
<TD><B><%= rs(i).Name %></B></TD>
<% Next %>
</TR>
<% For j = 1 To 5 %>
<TR>
<% For i = 0 To rs.Fields.Count - 1 %>
<TD><%= rs(i) %></TD>
<% Next %>
</TR>
<%
rs.MoveNext
Next
rs.Close
Cn.Close
%>
</TABLE>
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
MySQL派生表联表查询实战过程
![](https://img.aspxhome.com/file/2023/4/95624_0s.png)
Element el-date-picker 日期选择器的使用
![](https://img.aspxhome.com/file/2023/6/126616_0s.png)
Python时间戳转换为字符串与字符串转换为时间戳
Pytorch中的Tensorboard与Transforms搭配使用
![](https://img.aspxhome.com/file/2023/2/62022_0s.png)
pandas将DataFrame的几列数据合并成为一列
关于Python函数的定义和参数
MYSQL教程:表达式操作符和数据类型转换
IIS+PHP添加对webp格式图像的支持配置方法
使用git处理github中提交有冲突的pull request的问题
![](https://img.aspxhome.com/file/2023/2/132442_0s.png)
解读python logging模块的使用方法
详解PHP变量传值赋值和引用赋值变量销毁
![](https://img.aspxhome.com/file/2023/0/55720_0s.png)
asp.net cookie清除的代码
一场关于YUI3/jQuery的精彩辩论
Python和C语言利用栈分别实现进制转换
![](https://img.aspxhome.com/file/2023/2/101222_0s.png)
Python 数据结构之树的概念详解
![](https://img.aspxhome.com/file/2023/8/78798_0s.png)
利用PHP实现词法分析器与自定义语言
php隐藏IP地址后两位显示为星号的方法
sql中 RecordCount=-1问题
css清除浮动的方法总结与选择
Django如何实现网站注册用户邮箱验证功能
![](https://img.aspxhome.com/file/2023/9/94049_0s.png)