Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Basics
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 6th, 2008, 08:06 PM
Registered User
Join Date: Aug 2008
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to declare the global variable in global.asax?

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
            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.
            Dim reader As SqlDataReader = cmd.ExecuteReader()
            If (reader.Read()) Then
                _totalNumberOfUsers = reader.GetValue(0)
                Session("totaluser") = _totalNumberOfUsers
                _totalNumberOfUsers = 0
            End If

            ' Close the reader and the connection
        Catch ex As Exception
        End Try

    End Sub

Thanks and regards,

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to declare global variable gaurav_jain2403 General .NET 3 February 21st, 2006 01:31 AM
what is global.asax? gaurav_jain2403 General .NET 1 February 3rd, 2006 02:40 PM
global.asax ashokparchuri ADO.NET 1 February 25th, 2005 08:40 AM
how to call Application Variable from global .asax ranakdinesh ASP.NET 1.0 and 1.1 Basics 2 August 6th, 2004 06:01 AM

All times are GMT -4. The time now is 07:04 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.