Public Shared Declaration

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Herfried K. Wagner [MVP]

    #16
    Re: Public Shared Declaration

    "Mythran" <kip_potter@hot mail.comREMOVET RAIL> schrieb:[color=blue]
    > conStr, from what I see, means connection string (conStr for short) :)[/color]

    Ooops :-).

    --
    M S Herfried K. Wagner
    M V P <URL:http://dotnet.mvps.org/>
    V B <URL:http://classicvb.org/petition/>

    Comment

    • Kevin

      #17
      Re: Public Shared Declaration

      Here is the comlete code block:
      ............... ............... ...
      Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
      System.EventArg s) Handles MyBase.Load
      'Put user code to initialize the page here
      Dim conStr As String = "Provider=Micro soft.Jet.OleDb. 4.0;data
      source=C:\Docum ents and Settings\kwlehm an\My Documents\Elena 1.mdb"
      Dim conn As OleDbConnection = New OleDbConnection (conStr)
      ............... ............... .....
      "Herfried K. Wagner [MVP]" wrote:
      [color=blue]
      > "Kevin" <Kevin@discussi ons.microsoft.c om> schrieb:[color=green]
      > > I'd like to declare my connection string as a public shared variable, to
      > > be
      > > used throughout my ASP. Net projected (created using VB.NET 2003).
      > >
      > > Below is the line of code:
      > > Public Shared conStr As String = "Provider=Micro soft.Jet.OleDb. 4.0;data
      > > source=C:\Docum ents and Settings\kwlehm an\My Documents\Elena 1.mdb"
      > >
      > > I am getting an error at Public Shared:
      > > "Shared is not valid on a local variable declaration"[/color]
      >
      > Where did you place this code?
      >
      > --
      > M S Herfried K. Wagner
      > M V P <URL:http://dotnet.mvps.org/>
      > V B <URL:http://classicvb.org/petition/>
      >
      >[/color]

      Comment

      • Cor Ligthert

        #18
        Re: Public Shared Declaration

        Did anybody understand what I wrote, I did not. :-)

        If you make the connection string shared, than you can use this code.

        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
        System.EventArg s) Handles MyBase.Load
        Dim conn As New OleDbConnection (MySharedClass. conStr)

        This assumes that you have used a shared class with the name MySharedClass.

        That I prefer above a module because than you can find more easy where it is
        placed.

        For the same you can construct the connection of course as well in that
        shared class. Don't forget than to open and close the connection as well
        everytime.

        I hope this helps

        Cor


        Comment

        • Herfried K. Wagner [MVP]

          #19
          Re: Public Shared Declaration

          Cor,

          "Cor Ligthert" <notmyfirstname @planet.nl> schrieb:[color=blue]
          > That I prefer above a module because than you can find more easy where it
          > is placed.
          >
          > For the same you can construct the connection of course as well in that
          > shared class. Don't forget than to open and close the connection as well
          > everytime.[/color]

          Note that you actually /can/ qualify a module's member by the module name if
          you want to do so!

          --
          M S Herfried K. Wagner
          M V P <URL:http://dotnet.mvps.org/>
          V B <URL:http://classicvb.org/petition/>

          Comment

          • Cor Ligthert

            #20
            Re: Public Shared Declaration

            Herfried,[color=blue]
            >
            > Note that you actually /can/ qualify a module's member by the module name
            > if you want to do so!
            >[/color]
            Probably, what is a module else than a (to often quick and dirty written)
            shared class.

            :-)

            Although that it is in an asking way written, an answer is not needed.
            However if you want, feel free.

            :-)

            Cor


            Comment

            • Cor Ligthert

              #21
              Re: Public Shared Declaration

              Kevin,

              When you made the connection shared (in a shared class in the way you
              showed) in a module you get it without that shared class name. (I prefer a
              shared class. It becomes in a module in my opinion complete unfindable after
              a while). note. For Herfried, my opinion. :-)

              Than you get something as this.
              [color=blue]
              > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
              > System.EventArg s) Handles MyBase.Load[/color]
              Dim conn As New OleDbConnection (MySharedClass. conStr)

              (For the same you can construct that connection of course as well in that
              shared class. Don't forget than to open and close it everytime)

              Cor



              Comment

              • Cor Ligthert

                #22
                Re: Public Shared Declaration

                Did anybody understand what I wrote, I did not. :-)

                If you make the connection string shared, than you can use this code.

                Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
                System.EventArg s) Handles MyBase.Load
                Dim conn As New OleDbConnection (MySharedClass. conStr)

                This assumes that you have used a shared class with the name MySharedClass.

                That I prefer above a module because than you can find more easy where it is
                placed.

                For the same you can construct the connection of course as well in that
                shared class. Don't forget than to open and close the connection as well
                everytime.

                I hope this helps

                Cor


                Comment

                • Herfried K. Wagner [MVP]

                  #23
                  Re: Public Shared Declaration

                  Cor,

                  "Cor Ligthert" <notmyfirstname @planet.nl> schrieb:[color=blue]
                  > That I prefer above a module because than you can find more easy where it
                  > is placed.
                  >
                  > For the same you can construct the connection of course as well in that
                  > shared class. Don't forget than to open and close the connection as well
                  > everytime.[/color]

                  Note that you actually /can/ qualify a module's member by the module name if
                  you want to do so!

                  --
                  M S Herfried K. Wagner
                  M V P <URL:http://dotnet.mvps.org/>
                  V B <URL:http://classicvb.org/petition/>

                  Comment

                  • Cor Ligthert

                    #24
                    Re: Public Shared Declaration

                    Herfried,[color=blue]
                    >
                    > Note that you actually /can/ qualify a module's member by the module name
                    > if you want to do so!
                    >[/color]
                    Probably, what is a module else than a (to often quick and dirty written)
                    shared class.

                    :-)

                    Although that it is in an asking way written, an answer is not needed.
                    However if you want, feel free.

                    :-)

                    Cor


                    Comment

                    Working...