By David O'Neill
In Part 1 we looked at how the original
function behaved. We then looked at how to use the
cloneNode() method of the XML DOM. In this
part we'll examine using
GetRows() and wrap up the article with an examination of the complete
code along with a live demo!
Recordset.GetRows() Instead of Iterating Through the Recordset
Performance tuning discussions everywhere conclude that using the
GetRows() method of the ADO
Recordset object is a more processing-efficient means of accessing the data within that recordset. The ADO
Recordset object is a pretty heavy object; it uses lots of memory and processing for what you get. The benefit is
that it is easy to use and works very well. The downside is it is slow to work with large amounts of data.
(To learn more about
GetRows() be sure to check out this
In the above code we were iterating through the recordset, accessing each of its fields on each row. It is much
more efficient (although more complicated) to use
GetRows() to retrieve a multi-dimensional array of
our data then we can destroy the recordset.
For illustration of what a multi-dimensional array looks like, I ran the following VB code and took a screenshot
of a watch on the array variable.
You can see that the first dimension contains the fields and the second dimension contains the data. We access the values almost the same way we would itterate through the rows then fields of a recordset. So, the finished code would be:
Well, that's about it. From testing these changes improved performance by over 30% on a large data set. Now, when dealing with fewer records the gain will not be as large since there is a certain amount of overhead associated with opening the data connection and whatnot. All in all, a fairly easy change that should make a sizeable improvement in the end. Be sure to check out the live demo!
About the Author
David O'Neill is an MCSD and has been doing Web application development for the past five years.