Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Pro VB Databases
|
Pro VB Databases Advanced-level VB coding questions specific to using VB with databases. Beginning-level questions or issues not specific to database use will be redirected to other forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 9th, 2005, 06:01 AM
Authorized User
 
Join Date: Jan 2005
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Default Want to get number of recs without opening rs

How to get number of records without opening recordset?

I have successfully established the connection to a database as follows

Dim conn As New ADODB.Connection
conn.Open "driver={Microsoft ODBC for Oracle};" & _
    "server=js;" & _
    "uid=hsonsche;pwd=hsons"
Set Cat = New ADOX.Catalog
Cat.ActiveConnection = conn

I have also succeeded in listing the tables contained in the database
in a combobox as follows:

Tbl = 1
Do While Tbl < Cat.Tables.Count
    If Trim$(UCase(Cat.Tables(Tbl).Type)) = "TABLE" Or Trim$(UCase(Cat.Tables(Tbl).Type)) = "VIEW" Then
        If Mid(Cat.Tables(Tbl).Name, 3, 1) <> "$" Then
            Downloader.Combo4Tables.AddItem Cat.Tables(Tbl).Name
        End If
    End If
    Tbl = Tbl + 1
Loop

Now the problem is that I need the combo4Tables should include Name_of_Table & Tables(Tbl).NumberofRecords

what is the syntax?

I would not like to use a recordset to first load the recs in it and then count them, is there a short cut way of doing this?


 
Old August 9th, 2005, 08:25 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there..

you can execute a query to get the recordcount.. use select count(*) from tablename. that way you will avoid opening a Rs to count records...

HTH

Gonzalo
 
Old August 10th, 2005, 12:44 AM
Authorized User
 
Join Date: Jan 2005
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your help.
I have tried to use the execute command but probably I need to correct it's syntax
ActiveCell.Offset(Tb, 2) = conn.Execute("select count(*) from " & Cat.Tables(Tbl).Name, 1, -1)

The error I get is "1004 Application Defined or Object defined error"

I greatly appreciate your support

Thanks & regards






Similar Threads
Thread Thread Starter Forum Replies Last Post
Trigger for new recs John2112 SQL Server 2000 4 March 30th, 2007 05:02 AM
Restircting number of rows in the chart (RS 2005) achalana Reporting Services 0 August 7th, 2006 05:40 PM
How to get # of recs without opening recordset amjad_mahmood Excel VBA 0 August 9th, 2005 05:49 AM
MS RS Changing Server port Number jcredk BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 0 September 2nd, 2004 03:48 AM
RS Manager and RS Server on 2 different computers Choose File BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 1 July 22nd, 2004 10:56 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.