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
Register
Register | FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Display Modes
  #1 (permalink)  
Old August 6th, 2008, 09: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
        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
 


Thread Tools
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 07:01 AM



All times are GMT -4. The time now is 06:26 PM.


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