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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Count of Columns in a recordset ?

Status
Not open for further replies.

royalcheese

Technical User
Dec 5, 2005
111
GB
Hey all

I have a recordset and want to know how many columns are in the returned query.

This is what I have already

Code:
'connection String to ALPHA server
cst = "Driver={SQL Native Client};Server=ALPHA;Database=HPR;UID=Admin;PWD=wooyay;"

'Set connection as ADODB
Set cn = CreateObject("ADODB.Connection")

'Open Connection
cn.Open cst

'Set the recordset
Set RsHPR = New ADODB.Recordset

'SQL statement
which = "Select * from [test_table] order by pk asc"
RsHPR.Open which, cn, adOpenKeyset, adLockOptimistic

'Counts Rows and will insert data 
a = 0
If Not RsHPR.EOF And Not RsHPR.BOF Then
Do While (RsHPR.EOF = False)
'Loads all the information from the first field of the record until the EOF
a = a + 1
RsHPR.MoveNext
Loop

Is anything i can do to calculate it ?


Mnay thanks in advance


Chriso the Simple III
 
More concise (and more efficient) is
Code:
With RsHPR
    If Not (.EOF And .BOF) Then
        Do Until .EOF
            'Loads all the information from the first field of the record until the EOF
            a = a + 1
            .MoveNext
        Loop
    End If
End With
The with block adds efficiency because you only have to evaluate the object pointer once for the entire with block, instead of once for each method call.

Bob

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top