Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Batch execute Recordset 2

Status
Not open for further replies.

gus121

Technical User
May 9, 2002
298
0
0
GB
Hi I have been using the following code to update a recorset. Could you show me how I can execute all these records in a batch command outside the Loop. In which I can roll back later in the page if there is a problem with later queries.

Do While Not Products.EOF
'For each sub-categories the child products are displayed for that site added
Dim Product_Mask
Product_Mask = SubCat_Mask_Dif + cint(Products("Mask").value)
Product_ID = Products("Product_ID").value

strSql= "UPDATE tblProducts SET mask = '" & Product_Mask & "' WHERE product_ID = '" & Product_ID & "';"
'objConn.Execute(strsql)

Products.Movenext
Loop
End If

Angus
 
Just use a begintrans on the connection object

objConn.begintrans
Do While Not Products.EOF
'For each sub-categories the child products are displayed for that site added
Dim Product_Mask
Product_Mask = SubCat_Mask_Dif + cint(Products("Mask").value)
Product_ID = Products("Product_ID").value

strSql= "UPDATE tblProducts SET mask = '" & Product_Mask & "' WHERE product_ID = '" & Product_ID & "';"
'objConn.Execute(strsql)

Products.Movenext
Loop
End If

Later in your code if all is well use a objConn.committrans other wise were you error use objConn.rollback. Of course error trapping isn't the best in ASP, you'll have to use on error resume next or check a return value, I assume you already have this implemented.

MrGreed

"did you just say Minkey?, yes that's what I said."
 
in addition to MrGreed's suggestion, i can think of two other ways off the top of my head to do this:

the first involves a "disconnected recordset" --- learn more at or from google.

the second might be to delay executing your SQL update string until after you have finished looping, i.e.,
Do While Not .EOF
strSql = strSql & "UPDATE tblProducts SET mask = '" & Product_Mask & "' WHERE product_ID = '" & Product_ID & "';"
' don't execute here, wait until after loop
.MoveNext
Loop
' now execute your massive SQL string
objConn.Execute(strSql)

if the number of loops will not be terribly large (i.e., less than maybe 10,000) this might work well for you.


good luck!
-f!
 
Thanks for both your help. I can now create better more scalable ASP applications! Improve Database data stability. thanks again for your help you have been most helpfull.

Angus
 
Hi just one more question. My web application updates a table. In the same script it queries the same table again. The result should be based on the changes I have made with the previous update query.
Using the method MCGreed highlighted. Would the objConn.committrans have to be commited before the result of the second query could be run to get the right result.
This obviously assumes that you already have executed the first update query with objConn.Execute(strsql).

Thanks for your help

Angus
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top