RecordCount2 Function:
Returns the record count returned from a given database Table.
Description:
The RecordCount2 function returns a long representing the record count returned for a given Table. Works either with MSAccess, MSSQL and MySQL. There are two required arguments: ConnString and TableName. ConnString must be set to a valid database connection string and TableName must be set to a valid Table name in your database. RecordCount2 returns Null if error handling is enabled and a problem is encountered while obtaining a record count.
Syntax:
long = RecordCount2(connstring, tableName)
Example:
<%
'--- Use RecordCount to determine the record count returned from a given Table Name.
Dim a, cn cn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.Mappath("/database/mydata.mdb") & ";" a = RecordCount2(cn, "YourTableName") Response.Write a & " Records Found!"
%>
ASP Source Code:
<%
Private Function RecordCount2(byVal connstring, byVal TableName) '--- MSAccess, MSSQL and MySQL Dim objCn, bErr1, bErr2, strErrDesc, objRs, strSQL On Error Resume Next Set objCn = Server.CreateObject("ADODB.Connection") objCn.Open ConnString If Err Then bErr1 = True Else strSQL = "SELECT COUNT(*) AS Record_Count FROM " & TableName Set objRs = objCn.Execute(strSQL) RecordCount2 = CLng(objRs("Record_Count")) objRs.Close Set objRs = Nothing If Err Then bErr2 = True strErrDesc = Err.Description End If End If objCn.Close Set objCn = Nothing On Error GoTo 0 If bErr1 then Err.Raise 5109, "RecordCount2 Function", "Bad connection string. Database cannot be accessed." RecordCount2 = Null ElseIf bErr2 then Err.Raise 5109, "RecordCount2 Function", strErrDesc RecordCount2 = Null End If End Function '--- RecordCount2
%>
|