**************************************
name: batch update using ado
description:ado has a great batch upda
te feature that not many people take adv
antage of. you can use it to update many
records at once without making multiple
round trips to the database. here is how
to use it.
by: found on the world wide web
inputs:none
returns:none
assumes:none
side effects:none
warranty:
code provided by planet source code(tm)
(http://www.planet-source-code.com) as
is, without warranties as to performanc
e, fitness, merchantability,and any othe
r warranty (whether expressed or implied
).
**************************************
<html>
<head><title>place document title here</title></head>
<body bgcolor=ffffff text=000000>
<%
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") = "paul") or (rs("au_fname") = "johnson") then
newval = "melissa"
else
newval = "paul"
end if
if err <> 0 then
%>
<b>error opening recordset</b>
<% else %>
<b>opened successfully</b><p>
<% end if %>
<h2>before batch update</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>
move randomly in the table and perform updates to table.<br>
<%
randomize
r1 = int(rnd*3) + 1 n itterations
r2 = int(rnd*2) + 1 n places skipped between updates
for i = 1 to r1
response.write "itteration: " & i & "<br>"
rs("au_fname") = newval
for j = 1 to r2
rs.movenext
response.write "move next<br>"
next
next
rs.updatebatch adaffectall
rs.requery
rs.movefirst
%>
<% rs.movefirst %>
<h2>after changes</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>
