
recordcount returning -1 when there are 50 records
Hi Matt,
Recordcount is an unreliable way of finding how many
records are in a recordset.
One way of getting an acurate record count out of a
recordset is to loop through it and increment a integer
variable for each loop, like this...
oRec.MoveFirst
dim i as integer
i = 0
do while not oRec.EOF
i = i + 1
oRec.MoveNext
Loop
msgbox i
There are other ways, but this one is pretty foolproof,
and will have a negligable impact on performance unless
you are dealing with thousands of records.
HTH
Ed Voss
MCP
Quote:
>-----Original Message-----
>Brand new to ADO.. just got the SDK and I'm fumbling
through it. Why would
Quote:
>the following return -1?
>Dim oCon, oRec
>set oCon = CreateObject("ADODB.Connection")
>set oRec = CreateObject("ADODB.RecordSet")
>'con.Open "Driver={SQL Server};Server=" & SERVER
& ";Database=" & DATABASE &
Quote:
>";Trusted_Connection=yes;"
>oCon.Open "DSN=PacerViews;" & "Uid=User;" & "Pwd=Pass"
>'oRec.Open "delete from " & TABLE & " where portcd = ' "
& portcode & " ' ",
>con, adOpenStatic
>oRec.Open "select * from FVAL_HOLD where PORTCD
= '051504' and PROFILE_ID =
Quote:
>107 ", oCon
>msgbox oRec.recordcount
>oRec.close
>Set oRec = Nothing
>Set oCon = Nothing
>I'm working in Windows Script right now..
>I read the deal about using .movelast before
calling .recordcount.. I tried
Quote:
>that but no luck. I've also tried different cursors and
such.. maybe I just
>didn't get the right combo?
>This Query works fine when I run it from WinSQL and
returns 50 records.
>TIA
>Matt
>.