ADO.Net (Why doesn't this work?)

  • Thread starter Thread starter Josh
  • Start date Start date
J

Josh

Here is my code:

'open connection to database
Dim ADOcon As New ADODB.Connection()
Dim rsOverdue As New ADODB.Recordset()
Dim sql As String

ADOcon.Open("allstaff_contact")

'query for high priority overdue prospects
sql = "SELECT * from contactdetail"
rsOverdue.Open(sql, ADOcon)

MsgBox(rsOverdue.RecordCount)

The message box shows -1. When I test for an open connection, that
works, so there must be something wrong with the recordset. Any ideas
what is wrong?

Thanks,
Josh
 
Josh said:
Here is my code:

'open connection to database
Dim ADOcon As New ADODB.Connection()
Dim rsOverdue As New ADODB.Recordset()
Dim sql As String

ADOcon.Open("allstaff_contact")

'query for high priority overdue prospects
sql = "SELECT * from contactdetail"
rsOverdue.Open(sql, ADOcon) rsOverdue.MoveLast()

MsgBox(rsOverdue.RecordCount)

The message box shows -1. When I test for an open connection, that
works, so there must be something wrong with the recordset. Any ideas
what is wrong?

Until you movelast, the RecordCount isn't populated.

David
 
It will never work--and you won't be able to MoveLast.
You asked for a server-side forward-only (RO) firehose data stream that does
not return the rowcount.
You'll need to ask for a cursor that does support a rowcount like a
client-side static.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
I tried this but to no avail:

'open connection to database
Dim ADOcon As New ADODB.Connection()
Dim rsOverdue As New ADODB.Recordset()
Dim sql As String

ADOcon.Open("allstaff_contact")

'query for high priority overdue prospects
sql = "SELECT * from contactdetail"
rsOverdue.Open(sql, ADOcon,ADODB.CursorTypeEnum.adOpenStatic)
rsOverdue.MoveLast()
MsgBox(rsOverdue.RecordCount)

I still get -1 in the message box. Can you suggest some code that will work please?

Thanks,
Josh
 
Set the connection cursorlocation to adUseClient

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
Back
Top