• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 534
  • Last Modified:

Running a count query for SQL in VB6

Im am trying to get a record count for a SQL table from VB6
i have tried the following but i dont know where the ouput(if there is going to be any) will be.
    Dim intCount As String
    Dim adoBEN As New ADODB.Command
    Dim rsBEN As New ADODB.Recordset
    adoBEN.ActiveConnection = "dsn=depfund"
    adoBEN.CommandText = "select count (*) from Beneficiary where service_number = '" & intsnum & " '"
    adoBEN.CommandType = adCmdText
    Set rsBEN = adoBEN.Execute()
    intCount = rsBEN
I also created a ado control and tried the following to no avail. It seems to work for a access db.
    adoCount.RecordSource = "select count (*) from Beneficiary where service_number = '" & intsnum & "'"
    txtCount = adoCount

i have run the query in analyzer and it works fine....i have also made sure the intsnum variable contains a value when run.
Please let me know what im doing wrong.
1 Solution
Get the RecordCount property on the ADODB.Recordset object

intCount = resBEN.RecordCount

txtCount = adoCount.RecordSet.RecordCount

Also look at these links
dolfie99Author Commented:
Thanks for that

the inCount did not work, but the second one did. Dont know why and dont really care now.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now