Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 149,460 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 2,114 people online right now. Registration is fast and FREE... Join Now!




Performance Issue Summing Across a Record in a DB Connection

 
Reply to this topicStart new topic

Performance Issue Summing Across a Record in a DB Connection

scalt
27 Jan, 2008 - 12:00 PM
Post #1

D.I.C Head
Group Icon

Joined: 22 Nov, 2007
Posts: 111



Thanked: 2 times
Dream Kudos: 25
My Contributions
Hi

I need to sum X number of fields in an entry of a database (actually an ADO connection to *.xls) for several thousand entries. The fields are all grouped together but X is subject to change. My current code is:

CODE

While Not RS.EOF
For j = intCol To intCol2
      sum += RS.Fields("F" + CStr(loopj)).Value
Next

SummaryAList.Add(sum)

sum = nothing

RS.MoveNext()

End While


It seems to be taking a really long time to do this. Does anyone have any suggestions that could possibly speed this up?

intCol and intCol2 are two column markers, sum is declared as double (values are in Excel spreadsheet and accurate to 10 DP)

EDIT:
I fixed the problem somewhat (it is about 2-3 times faster now) by putting each line into an array, then performing the loop on the array. It seems as though the recordset is much slower when moving across it rather than down it.

CODE

RSArray = RS.GetRows(1)
For j = intCol To intCol2
      sum += RSArray(j, 0)
Next


This post has been edited by scalt: 27 Jan, 2008 - 12:48 PM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 01:51PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month