473,795 Members | 2,826 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

creating a global variable to use throughout the application

I'm making an app that inputs into multiple tables. I'm using the
SCOPE_IDENTITY( ) SQL function for foreign key purposes. I input into the
main table first and retrieve the scope_identity( ) and then insert into
related tables using the scope_identity( ) number as the foregin key entry
for each table.

Each of these inputs is done within the code for seperate buttons. How do I
create a variable (a string type) I can use throughout the application? I'd
populate it with the scope_identity( ) and would want that number to remain
in that variable until I manually clear it out.

I tried this at the top of the page (code file) before any other
subroutines.

Partial Class inventory_index
Inherits System.Web.UI.P age
Public strScopeID As String

But if I try a response.write( strScopeID) after I populate it (at least I
think I do), I get the error:

Object reference not set to an instance of an object.

TIA,

Jim
Nov 1 '08 #1
2 1780
On Sat, 01 Nov 2008 01:20:06 +0100, Jim in Arizona <ti*******@hotm ail.com>
wrote:
I'm making an app that inputs into multiple tables. I'm using the
SCOPE_IDENTITY( ) SQL function for foreign key purposes. I input into the
main table first and retrieve the scope_identity( ) and then insert into
related tables using the scope_identity( ) number as the foregin key entry
for each table.

Each of these inputs is done within the code for seperate buttons. How
do I
create a variable (a string type) I can use throughout the application?
I'd
populate it with the scope_identity( ) and would want that number to
remain
in that variable until I manually clear it out.

I tried this at the top of the page (code file) before any other
subroutines.

Partial Class inventory_index
Inherits System.Web.UI.P age
Public strScopeID As String

But if I try a response.write( strScopeID) after I populate it (at least I
think I do), I get the error:

Object reference not set to an instance of an object.

TIA,

Jim

I am not absolutely sure whether I understand your question correctly, so
please bear with me if the following suggestion does not help you at all :)

To write the application variable from within a Page:
Application("Sc opeID") = "something from the db"

To read and output the application variable from within a Page:
Response.Write( Application("Sc opeID"))

--
Joern Schou-Rode
http://malamute.dk/
Nov 1 '08 #2
I am not absolutely sure whether I understand your question correctly, so
please bear with me if the following suggestion does not help you at all
:)

To write the application variable from within a Page:
Application("Sc opeID") = "something from the db"

To read and output the application variable from within a Page:
Response.Write( Application("Sc opeID"))

--
Joern Schou-Rode
http://malamute.dk/
I ended up going off of your example and so far, with a small test that I
did, this seems to be the solution that I need.

Dim strScopeID, strSQLSI as String

strSQLSI = "SELECT SCOPE_IDENTITY( )"

Dim objConnection As New SqlConnection(s trConn)
Dim objCommand As New SqlCommand(strS QL, objConnection)
Dim objCmdSI As New SqlCommand(strS QLSI, objConnection)

objConnection.O pen()
objCommand.Exec uteNonQuery()
strScopeID = objCmdSI.Execut eScalar()
objConnection.C lose()

Application.Loc k()
Application("SI ") = strScopeID.ToSt ring
Application.UnL ock()

Response.Write( Application("SI ").ToString )
Thanks Joern!

Nov 3 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1696
by: refer_to_website | last post by:
I realize that if I want a global VARIABLE, I can DIM a session variable in global.asa. I.e. Static oCurrentPerson As New Person() in the Session_Start routine) but attempting to access Session("oCurrentPerson").PersonId does not work in a form's code-behind, because it is an object, not a variable (unable to access PROPERTIES of the object variable). How I declare and use a global OBJECT in VB.NET?
9
2381
by: Tony Johansson | last post by:
Hello! I know it's bad design to use global variables. I just want to ask a question about them. Is global variables and global static variables the same. These are define outside any function at the top of the a file where you have them. //Tony
17
5634
by: MLH | last post by:
A97 Topic: If there is a way to preserve the values assigned to global variables when an untrapped runtime error occurs? I don't think there is, but I thought I'd ask. During development, I'm constantly running tests on imperfect code. On of the cumbersome jobs encountered is reassigning global vars their values after a close encounter with an untrapped runtime error. Rather than writing a procedure to simply reassign them all with a...
11
2571
by: Capstar | last post by:
Hi, I am working on an application, which will run embedded without an OS. The app is build up out of a couple of well defined parts. At first I wanted to keep those parts seperated and use opaque data types to transfer information in between them. At some stage I was stuck and needed to make a variable global, and I also needed to make the struct declaration public to some other parts. Looking through the code I found out that lots...
4
3538
by: BB | last post by:
Hello all, I might be missing something here, but am trying to understand the difference between using application-level variables--i.e. Application("MyVar")--and global variables--i.e. public myVar as string, etc. It seems to me that the scope and duration are the same, as they both are there while the application is running, and both go away when it quits. I presume that one difference is that the application state can be "flushed," such...
2
3533
by: PRTC | last post by:
I'm trying to use the global.asax in my new web aplication proyect using the Application start to store my connection string GLOBAL.ASAX.vb Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs) Dim objConnection As OleDbConnection Dim daContent As OleDbDataAdapter Dim objDataReader As OleDbDataReader
1
1575
by: Darin | last post by:
I have an application that is one EXE with mutliple DLL's. In one of the DLL's (libs.dll) that the EXE has refeneced, I have: Public Class Globals Public Shared gLogin as String End Class This variable is ued throughout my program in libs.dll, and other DLLs. The user then starts up another occurance of the application. They login
44
3649
by: fabio | last post by:
Why? i' ve heard about this, the usage of global vars instead of locals is discouraged, but why? thx :)
1
29384
weaknessforcats
by: weaknessforcats | last post by:
C++: The Case Against Global Variables Summary This article explores the negative ramifications of using global variables. The use of global variables is such a problem that C++ architects have called it polluting the global namespace. This article explores what happens when the global namespace becomes polluted and how to avoid this condition. The opinions expressed in this article are those of the author alone although many have...
0
9672
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9519
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10438
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10001
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9042
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6780
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.