Monday, December 17, 2007

How to get the total of records in the table

How to get the total of records in the table

S T E P - 1

- We have a "member" table and we need to show the total of member in the table.

- Now, we create a RecordSet to open the member table.

<%

Const adOpenKeyset = 1, adLockPessimistic = 2

Dim oConn

Dim oRs

Set oConn = Server.CreateObject("ADODB.Connection")

oConn.Open "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("cp.mdb")

Set oRs = Server.CreateObject("ADODB.Recordset")

oRs.Open "member", oConn, adOpenKeyset, adLockPessimistic

%>

S T E P - 2

- we can use the RecordCount to get the value.

- Finally, please close the recordSet and Connection.

<%

Response.write "

Total Members : " & oRs.RecordCount & "
"

oRs.Close

oConn.Close

Set oRs = Nothing

Set oConn = Nothing

%>

No comments: