INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Visual Basic (Microsoft) Versions 5/6 FAQ

Database

Looping through large recordsets using ADODB.Field pointers by manitoba
Posted: 29 Jan 04

If your recordset has a lot of data - hundreds or thousands of rows, use a pointer to the column to improve performance.  It is much faster than doing this:

rsData("column_a").Value

Here is an example:

'Declare
Dim objConn As ADODB.Connection
Dim rsData As ADODB.Recordset
Dim objFieldX As ADODB.Field
Dim objFieldY As ADODB.Field
Dim strCmd As String

'Initialize
Set objConn = New ADODB.Connection
    
'Open connection
mobjDBConn.Open "....my connection string..."

'Fetch data
Set rsData = mobjConn.Execute("...my sql...")


'Get a pointer to the fields    
Set objFieldX = rsData("column_x")
Set objFieldY = rsData("column_y")

If rsData.BOF And rsData.EOF Then
    'Do something if recordset is empty
Else
    Do Until rsData.EOF
        'Do something with the data
        'a = objFieldX.Value
        'b = objFieldY.Value

        rsData.MoveNext
    Loop
End If

'Close connection
If objConn.State <> adStateClosed Then
    objConn.Close
End If
    
'Clean up
Set rsData = Nothing
Set objConn = Nothing
Set objFieldX = Nothing
Set objFieldY = Nothing

Back to Visual Basic (Microsoft) Versions 5/6 FAQ Index
Back to Visual Basic (Microsoft) Versions 5/6 Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close