WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

OLE COM ADO CDO ADSI LDAP
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Get Number of Records in Each Table

 Keywords: Row Count rowcount Number Records Tables

Sample code:

; ======= Winbatch: UDF to Return Records in Database Tables ============= ;
;  1. This Example uses ACCESS, but should work with other Providers       ;
;  2. I use the SELECT COUNT instead of rowcount() as it will also         ;
;     work if an optional WHERE clause is sent as a parameter              ;
;                                                                          ;
;  Stan Littlefield  ( stanl@btitelecom.net )    July 1, 2001              ;
; ======================================================================== ;

#DefineFunction GetCount(cMDB,cat)
cConn  = cat.ActiveConnection
nt     = cat.Tables
nCnt   = nt.count()
If nCnt==0
   ObjectClose(cat)
   Return(-1)
Endif
aTables = ArrDimension(nCnt,3)
BoxOpen(cMDB,"Table ")
For i=0 To nCnt-1
   tbl = cat.Tables(i)
   aTables[i,0]   = tbl.Name
   aTables[i,1] = tbl.Type
   Boxtext(StrCat("Table ",aTables[i,0] ) )
Next

RS  = ObjectOpen("ADODB.Recordset")
For i=0 To ncnt-1
   If aTables[i,1] == "TABLE"
      cSQL = StrCat( "SELECT COUNT (*) FROM ",aTables[i,0] )
      RS.Open(cSQL,cConn,1,4)
      fld = RS.Fields(0)
      aTables[i,2] = fld.Value
      RS.Close()
   Endif
Next
BoxShut()
ObjectClose(RS)
ObjectClose(cat)
Return(aTables)
#EndFunction

; ==== Script Starts Here  =============
cMDB   = AskFileName("Select ACCESS Database",".\","MDB Files|*.mdb|","*.mdb",1)
If cMDB == ""
   Return
Endif
cat    = ObjectOpen("ADOX.Catalog")
cat.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%cMDB%;"

aTables = GetCount(cMDB,cat)

If VarType(aTables) == 256
   For i=0 To ArrInfo(aTables,1) -1
      If aTables[i,1] == "TABLE"
         message( StrCat("Table: ",aTables[i,0]),Strcat("Records: ",aTables[i,2]) )
      Endif
   Next
Else
   message("Error in %cMDB%","No Tables in Database")
Endif
exit

Article ID:   W15226
File Created: 2002:09:05:13:50:44
Last Updated: 2002:09:05:13:50:44