470,849 Members | 1,133 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,849 developers. It's quick & easy.

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 1692
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by refer_to_website | last post: by
9 posts views Thread by Tony Johansson | last post: by
11 posts views Thread by Capstar | last post: by
2 posts views Thread by PRTC | last post: by
1 post views Thread by Darin | last post: by
44 posts views Thread by fabio | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.