Monday, May 24, 2010

Code to Make a counter of registered emails on my ASP home page using SQL?

I want to make a counter on my home page with ASP pulling from MS SQL based on the number of people registered as users.

Code to Make a counter of registered emails on my ASP home page using SQL?
Once again, I urge people to state WHICH VERSION of ASP?





In ASP.NET / VB, include System.Data and System.Data.SqlClient in your namespaces, and have a label on your page named lblCounter. Call the subroutine below in your Page_Load subroutine.





Also, in the code below, registered users table is the name of the table where you store your e-mail addresses for registered users.





Sub GetRegisteredUserCount()


Dim objConn As New SqlConnection( "connection string" )


Dim objCmd As New SqlCommand( "SELECT COUNT(*) AS totalmembers FROM registered users table" )





objConn.Open()


Dim objReader As SqlDataReader = objCmd.ExecuteReader()


objReader.Read()


lblCounter.Text = "There are " + FormatNumber( objReader( "totalmembers") + " registered users."


objConn.Close()





objCmd.Dispose()


objConn.Dispose()


End Sub





In ASP 3.0 VBScript:





%26lt;%


Dim objConn = Server.CreateObject( "ADODB.Connection" )


objConn.Open "your connection string"





Dim objRs= Server.CreateObject( "ADODB.Recordset" )


objRs.Open "SELECT COUNT(*) AS totalmembers FROM registered users table", objConn





Response.Write "There are " %26amp; objRs( "totalmembers") %26amp; " registered users."





objConn.Close()


Set objRs = Nothing


Set objConn = Nothing


%%26gt;

flower bouquet

No comments:

Post a Comment