eojhan
asked on
VB- ADO Returns a recordcount of -1
This should be a really easy one. I have the following code:
SQLConnect = "Provider=SQLOLEDB;Data Source=CLUSTERNAME\CLUSTER INSTANCE;I nitial Catalog=MyTable;Integrated Security=SSPI;"
Conn1.ConnectionString = SQLConnect
Conn1.Open
Cmd1.ActiveConnection = Conn1
Cmd1.CommandText = "Select MyColumn from MyTable where Need2Publish = 1"
Set Rs1 = Cmd1.Execute
Rs1.MoveFirst
i = 1
x = 1
intCount = Rs1.RecordCount
MsgBox intCount
This always produces a RecordCount of -1, even though there are 2 records? I know for a fact there are two records because if I do this:
intCount = 2
If intCount > 0 Then
ReDim strVarName(intCount)
Do Until Rs1.EOF
strVarName(i) = Rs1.Fields(0).Value
MsgBox (strVarName(i))
Rs1.MoveNext
i = i + 1
Loop
End If
It returns my 2 values in the message box...
Does anyone have an explanation to this?
TIA,
Owen
SQLConnect = "Provider=SQLOLEDB;Data Source=CLUSTERNAME\CLUSTER
Conn1.ConnectionString = SQLConnect
Conn1.Open
Cmd1.ActiveConnection = Conn1
Cmd1.CommandText = "Select MyColumn from MyTable where Need2Publish = 1"
Set Rs1 = Cmd1.Execute
Rs1.MoveFirst
i = 1
x = 1
intCount = Rs1.RecordCount
MsgBox intCount
This always produces a RecordCount of -1, even though there are 2 records? I know for a fact there are two records because if I do this:
intCount = 2
If intCount > 0 Then
ReDim strVarName(intCount)
Do Until Rs1.EOF
strVarName(i) = Rs1.Fields(0).Value
MsgBox (strVarName(i))
Rs1.MoveNext
i = i + 1
Loop
End If
It returns my 2 values in the message box...
Does anyone have an explanation to this?
TIA,
Owen
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Why does aduseclient work and aduseserver not? Why is this the only way to get at the recordcount property?
strSQL="Select Count(*) from tblTableName"
rsGetData.Open