Microsoft KB Archive/108150
Article ID: 108150
Article Last Modified on 1/8/2003
- Microsoft Visual Basic 3.0 Professional Edition
This article was previously published under Q108150
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.
- Start a new project in Visual Basic. Form1 is created by default.
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
- 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.
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 query words: 3.00