AddNew and UpdateBatch in ADO

T

Tony29

Bit of trouble here.

For aItem = 0 To UBound(InputArray, 1)
rs.AddNew
With rs
For fItem = 0 To rs.Fields.Count - 1
.Fields(fItem) = InputArray(aItem, fItem)
Next fItem
End With
rs.Update
rs.UpdateBatch
Next aItem

1. This puts an array out to a table. The code produces the required result
but why must I put rs.UpdateBatch inside the loop rather than outside the
loop (where I thought it would be a good idea to place it so that all the
'updates' occur in memory before the completion of the processing and then in
one big action it is all sent off to the database - assuming this would be
faster). If I place rs.UpdateBatch outside the loop I get an error
indicating 'Number of rows with pending changes exceed the limit'

2. In the logic that calls this I immediately follow putting the array out
to the table with a call to a routine that retrieves the table into a new
array (this is how I achieve sorting and grouping of the data in the array).
Again, the logic works fine and if I 'step' through the code I get all the
right results. But if I run the code with no breaks or step throughs, the
retrieval of the table data into the 2nd array seems to fail - as if it
hasn't had enough time to finish off flushing the record set from the first
array out to the database

Sample calling logic ...

Call LoadDBFromArray("tablename", array(), ErrorCode)
newarray = LoadArrayFromDB("SELECT ... tablename ... ", RowsReturned)

Thanks ... Tony
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top