updating multiple listings from one form
I am using the following code to update a group of
listings. It works, sometimes. And other times
it gets stuck when it gets to the part of the
show_updated function where it is supposed to
display data from the table that was just
updated.
What might be the problem here?
Another, perhaps related question:
In my code each lisiting is updated with its own
rs1.update command. Is there some way
to update all the listings into the db table in one
update action? This would mean less trips back
and forth from the asp page to the db file.
case Request.Form("sub_update_institutions")<>""
sqlstr="SELECT * FROM institutions;"
rs1.Open sqlstr,con,3,3
do until item_index >request.Form.Count-2
for i=1 to 7 step 1
rs1.fields(i)=request.form(item_index)
item_index=cint(item_index)+1
next
rs1.update
rs1.MoveNext()
loop
rs1.MoveFirst
rs1.close
call show_updated()
Andy Kohlenberg
Jerusalem, Israel
Peter J. Boettcher posted this at 14:34 — 28th May 2001.
They have: 812 posts
Joined: Feb 2000
My first recommendation would be to move this to a stored procedure (if possible). If that isn't possible then consider using the UpdateBatch method. You'll have to add a LockType of adLockBatchOptimistic, and a CursorType of adOpenKeyset.
Example:
On Error Resume Next
case Request.Form("sub_update_institutions")<>""
sqlstr="SELECT * FROM institutions;"
rs1.Open sqlstr,con,3,3
do until item_index >request.Form.Count-2
for i=1 to 7 step 1
rs1.fields(i)=request.form(item_index)
item_index=cint(item_index)+1
next
rs1.MoveNext()
loop
If Err.number = 0 Then
rs1.UpdateBatch
Else
rs1.CancelBatch
End If
rs1.MoveFirst
rs1.close
call show_updated()
PJ | Are we there yet?
pjboettcher.com
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.