473,836 Members | 1,487 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Public Shared Declaration

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"

I know that I've used Public Shared many times, yet never doing an ASP. NET
project. I am just learning ASP. NET and am not too familiar.

Any advice would be appreciated.

Thanks,
Kevin
Nov 21 '05 #1
23 8233

"Kevin" <Ke***@discussi ons.microsoft.c om> wrote in message
news:05******** *************** ***********@mic rosoft.com...
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"

I know that I've used Public Shared many times, yet never doing an ASP.
NET
project. I am just learning ASP. NET and am not too familiar.

Any advice would be appreciated.

Thanks,
Kevin


Is the conStr var inside a Module?

Mythran

Nov 21 '05 #2
"Kevin" <Ke***@discussi ons.microsoft.c om> schrieb:
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"


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/>

Nov 21 '05 #3
Here is the entire 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)
............... ...

"Mythran" wrote:

"Kevin" <Ke***@discussi ons.microsoft.c om> wrote in message
news:05******** *************** ***********@mic rosoft.com...
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"

I know that I've used Public Shared many times, yet never doing an ASP.
NET
project. I am just learning ASP. NET and am not too familiar.

Any advice would be appreciated.

Thanks,
Kevin


Is the conStr var inside a Module?

Mythran

Nov 21 '05 #4
"Kevin" <Ke***@discussi ons.microsoft.c om> schrieb:
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)


You'll have to put the declaration of the 'conStr' "variable" outside the
'Sub' procedure. I assume that the prefix 'con' indicates a constant, thus
you can use 'Const' instead of 'Dim'.

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

Nov 21 '05 #5

"Kevin" <Ke***@discussi ons.microsoft.c om> wrote in message
news:99******** *************** ***********@mic rosoft.com...
Here is the entire 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)
............... ..

"Mythran" wrote:


You can't put Public inside of a method. Try the following:

Public conStr As String = "..."

Public Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) _
Handles MyBase.Load
Dim conn As OleDbConnection = New OleDbConnection (Me.conStr)
End Sub

HTH,
Mythran

Nov 21 '05 #6

"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> wrote in message
news:O$******** ******@TK2MSFTN GP12.phx.gbl...
"Kevin" <Ke***@discussi ons.microsoft.c om> schrieb:
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)


You'll have to put the declaration of the 'conStr' "variable" outside the
'Sub' procedure. I assume that the prefix 'con' indicates a constant,
thus you can use 'Const' instead of 'Dim'.

--


Beat me to it :P

conStr, from what I see, means connection string (conStr for short) :)

Mythran
Nov 21 '05 #7
"Mythran" <ki********@hot mail.comREMOVET RAIL> schrieb:
conStr, from what I see, means connection string (conStr for short) :)


Ooops :-).

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Nov 21 '05 #8
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:
"Kevin" <Ke***@discussi ons.microsoft.c om> schrieb:
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"


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/>

Nov 21 '05 #9
"Kevin" <Ke***@discussi ons.microsoft.c om> schrieb:
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"


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/>

Nov 21 '05 #10

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

Similar topics

1
4016
by: May | last post by:
greetings, i came across a function while browsing thru the net. This function is created in a component. what i am curious to know is, is this the correct way to create a function using: Public Shared Function name() As String Don't we need some sort of parameter passing to use the "As String"? Maybe something like this: Public Shared Function name(ByVal fname As String) i am also curious as to why we need to use "Public Shared"
3
1816
by: Joe Fallon | last post by:
I have a Shared varibale in a base class and all the Shared methods in the sub-classes use it (and CHANGE it). I thought I was saving myself the "trouble" of Dimming this variable inside each Shared method. But now I wonder if I will have a problem in a multi-user environment with code that changes this variable. Can someone please review this sample code and let me know if it is an issue? Also what is the best way to clean it up? Dim...
10
3684
by: darrel | last post by:
I'm still trying to sort out in my head the differences between public and shared when referring to declaring properties or variables. This is my understanding: shared - akin to a 'global' variable for the application. Any other code within the application can access it. public - can be shared across the application if instatiated. Does that sound about right? It seems these are more useful for methods rather than variables. Most of...
4
45206
by: Chris | last post by:
Hello, I'm just getting started with VB and am new to the group, so please excuse what may seem to be a rudimentary question. I've been writing basic programs and have noticed that the syntax for some of these functions have been set up with the keywords "Public Shared Function" (for example, the Trim function) and others are set up just as "Public
2
3032
by: Darrel | last post by:
I'm working on an app where the ASPX pages aren't precompiled with the class.vb files I'm. This is so people can add their own ASPX pages down the road to the app (the .aspx pages become 'templates' in a way). As such, each template has a function call at the top: <% retrieveData() %> and then within the page, wherever they want to show some text from the db, they just use one of the variables sent in the vb file:
8
2022
by: Al | last post by:
I'd like to create Class Library in VB 2005, which has a property accessible by external programs. I decided to include 1 Class with 1 property in this project. I placed this code in Class: Public Class COM Private mMyProp As String Public Property MyProp() As String
6
2904
by: Aussie Rules | last post by:
Hi, THe following code (in c# has been provided to me as an answer in another question).. however I can work out where to place the code. I need a public string so that i can access a string value in the HTML source of a page.. The public sting is below.. So this go in a class file? the code behind file? or a global module?
0
9814
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
9666
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
10838
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
10544
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
6977
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
5645
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5821
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4447
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
2
4010
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.