欢迎光临
我们一直在努力

使用ADO的批量更新方法UpdateBatch

建站超值云服务器,限时71元/月

**************************************

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>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 使用ADO的批量更新方法UpdateBatch
分享到: 更多 (0)

相关推荐

  • 暂无文章