How to Count Rows Affected Before Query in VB Prof ver 3.0

Last reviewed: June 21, 1995
Article ID: Q108150
The information in this article applies to:

- Professional Edition of Microsoft Visual Basic for Windows, version 3.0

SUMMARY

This article shows by example how to count the number of rows affected by a query before executing the query. You can execute a Select query using the same Where clause that your action query will use. Then you can examine the return value. This is an excellent practice before using the SQL Delete or Update methods.

MORE INFORMATION

Step-by-Step Example

  1. Start a new project in Visual Basic. Form1 is created by default.

  2. Double-click the form to open its code window. Add the following code to the Form Load event:

       Sub Form_Load ()
          Dim db As database
          Dim ds As dynaset
          Set db = OpenDatabase("c:\vb3\biblio.mdb")
          ' Place the following Set statement on one, single line:
          Set ds = db.CreateDynaset("SELECT COUNT(*) as alias
             FROM Authors where AU_ID > 10")
          Debug.Print ds(0)
       End Sub
    
    

  3. Start the program or press the F5 key. The Debug window will display a count of 36. To end the program, close the form.

You can check the contents of the BIBLIO.MDB file by opening it with Microsoft Access or with the Data Manager provided with Visual Basic. You can run the Data Manager program from the Window menu in Visual Basic, or you can select DATAMGR.EXE in the Visual Basic directory and run it from the Windows File Manager.

REFERENCES

The VISDATA.MAK file installed in the VB3\SAMPLES\VISDATA directory loads extensive examples of data access. The VISDATA sample program uses every data access function in Visual Basic. You can refer to the VISDATA source code for examples of how to use each data access function.


Additional reference words: 3.00
KBCategory: kbprg kbcode
KBSubcategory: APrgDataOther


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: June 21, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.