Hi Support,
Currently i am using visual studio 2008 and .net 3.5 to develop a system. Below code are taken from global.asax for your reference. What i need help is how to declare the global variable -Private Shared _totalNumberOfUsers As Integer = 0 - in global.asax in order to enable it to be read from all other aspx pages. Help urgently needed.
<%@ Application Language="
VB" %>
<%@ Import Namespace="System.data.sqlclient" %>
<%@ Import Namespace="System.data" %>
<%@ Import Namespace="System.configuration" %>
<%@ Import Namespace="System.configuration.configurationsetti ngs" %>
<%@ Import Namespace="System.web" %>
<%@ Import Namespace="System.Web.SessionState" %>
<%@ Import Namespace="System" %>
<script runat="server">
Private strConn As String = ConfigurationManager.ConnectionStrings("connstr"). ConnectionString
Dim cnn As SqlConnection = New SqlConnection(strConn)
Private Shared _totalNumberOfUsers As Integer = 0
'Public _currentNumberOfUsers As Integer = 0
'Private strConn As String = ConfigurationManager.ConnectionStrings("connstr"). ConnectionString
'Dim cnn As SqlConnection = New SqlConnection(strConn)
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs on application startup
' Fires when the application is started
Try
Dim cmd As SqlCommand = New SqlCommand()
cmd.Connection = cnn
' Build SELECT statement
cmd.CommandText = "SELECT numberofhits FROM counter " & _
"WHERE countertype = 'UserCounter'"
' Open the connection, and execute the SQL statement.
cnn.Open()
Dim reader As SqlDataReader = cmd.ExecuteReader()
If (reader.Read()) Then
_totalNumberOfUsers = reader.GetValue(0)
Session("totaluser") = _totalNumberOfUsers
Else
_totalNumberOfUsers = 0
End If
' Close the reader and the connection
reader.Close()
cnn.Close()
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
End Sub
Thanks and regards,
Calyn