How to Count Rows Affected Before Query in VB Prof ver 3.0
ID: Q108150
|
The information in this article applies to:
-
Microsoft Visual Basic Professional Edition 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
- 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.
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 query words:
3.00
Keywords :
Version : WINDOWS:3.0
Platform : WINDOWS
Issue type :