Running a count query for SQL in VB6

Posted on 2006-06-01
Last Modified: 2013-11-12
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.
Question by:dolfie99
    LVL 15

    Accepted Solution

    Get the RecordCount property on the ADODB.Recordset object

    intCount = resBEN.RecordCount

    txtCount = adoCount.RecordSet.RecordCount

    Also look at these links

    Author Comment

    Thanks for that

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


    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    Introduction Many of the most common information processing tasks require sorting data sets.  For example, you may want to find the largest or smallest value in a collection.  Or you may want to order the data set in numeric or alphabetical order. …
    Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now