creating a global variable to use throughout the application

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jim in Arizona

    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


  • Joern Schou-Rode

    #2
    Re: creating a global variable to use throughout the application

    On Sat, 01 Nov 2008 01:20:06 +0100, Jim in Arizona <tiltowait@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

    Comment

    • Jim in Arizona

      #3
      Re: creating a global variable to use throughout the application

      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!



      Comment

      Working...