473,385 Members | 1,282 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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.Page
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 1769
On Sat, 01 Nov 2008 01:20:06 +0100, Jim in Arizona <ti*******@hotmail.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.Page
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("ScopeID") = "something from the db"

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

--
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("ScopeID") = "something from the db"

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

--
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(strConn)
Dim objCommand As New SqlCommand(strSQL, objConnection)
Dim objCmdSI As New SqlCommand(strSQLSI, objConnection)

objConnection.Open()
objCommand.ExecuteNonQuery()
strScopeID = objCmdSI.ExecuteScalar()
objConnection.Close()

Application.Lock()
Application("SI") = strScopeID.ToString
Application.UnLock()

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
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...
9
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...
17
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...
11
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...
4
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...
2
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,...
1
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 ...
44
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
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.