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=Microsoft.Jet.OleDb.4.0;data
source=C:\Documents and Settings\kwlehman\My Documents\Elena1.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 23 8189
"Kevin" <Ke***@discussions.microsoft.com> wrote in message
news:05**********************************@microsof t.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=Microsoft.Jet.OleDb.4.0;data source=C:\Documents and Settings\kwlehman\My Documents\Elena1.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
"Kevin" <Ke***@discussions.microsoft.com> 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=Microsoft.Jet.OleDb.4.0;data source=C:\Documents and Settings\kwlehman\My Documents\Elena1.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/>
Here is the entire code block:
..................
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Dim conStr As String = "Provider=Microsoft.Jet.OleDb.4.0;data
source=C:\Documents and Settings\kwlehman\My Documents\Elena1.mdb"
Dim conn As OleDbConnection = New OleDbConnection(conStr)
..................
"Mythran" wrote: "Kevin" <Ke***@discussions.microsoft.com> wrote in message news:05**********************************@microsof t.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=Microsoft.Jet.OleDb.4.0;data source=C:\Documents and Settings\kwlehman\My Documents\Elena1.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
"Kevin" <Ke***@discussions.microsoft.com> schrieb: Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here Dim conStr As String = "Provider=Microsoft.Jet.OleDb.4.0;data source=C:\Documents and Settings\kwlehman\My Documents\Elena1.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/>
"Kevin" <Ke***@discussions.microsoft.com> wrote in message
news:99**********************************@microsof t.com... Here is the entire code block: ................. Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here Dim conStr As String = "Provider=Microsoft.Jet.OleDb.4.0;data source=C:\Documents and Settings\kwlehman\My Documents\Elena1.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
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:O$**************@TK2MSFTNGP12.phx.gbl... "Kevin" <Ke***@discussions.microsoft.com> schrieb: Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here Dim conStr As String = "Provider=Microsoft.Jet.OleDb.4.0;data source=C:\Documents and Settings\kwlehman\My Documents\Elena1.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
"Mythran" <ki********@hotmail.comREMOVETRAIL> 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/>
Here is the comlete code block:
.................................
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Dim conStr As String = "Provider=Microsoft.Jet.OleDb.4.0;data
source=C:\Documents and Settings\kwlehman\My Documents\Elena1.mdb"
Dim conn As OleDbConnection = New OleDbConnection(conStr)
...................................
"Herfried K. Wagner [MVP]" wrote: "Kevin" <Ke***@discussions.microsoft.com> 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=Microsoft.Jet.OleDb.4.0;data source=C:\Documents and Settings\kwlehman\My Documents\Elena1.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/>
"Kevin" <Ke***@discussions.microsoft.com> 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=Microsoft.Jet.OleDb.4.0;data source=C:\Documents and Settings\kwlehman\My Documents\Elena1.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/>
Here is the entire code block:
..................
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Dim conStr As String = "Provider=Microsoft.Jet.OleDb.4.0;data
source=C:\Documents and Settings\kwlehman\My Documents\Elena1.mdb"
Dim conn As OleDbConnection = New OleDbConnection(conStr)
..................
"Mythran" wrote: "Kevin" <Ke***@discussions.microsoft.com> wrote in message news:05**********************************@microsof t.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=Microsoft.Jet.OleDb.4.0;data source=C:\Documents and Settings\kwlehman\My Documents\Elena1.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
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. Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
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
"Kevin" <Ke***@discussions.microsoft.com> schrieb: Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here Dim conStr As String = "Provider=Microsoft.Jet.OleDb.4.0;data source=C:\Documents and Settings\kwlehman\My Documents\Elena1.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/>
"Kevin" <Ke***@discussions.microsoft.com> wrote in message
news:99**********************************@microsof t.com... Here is the entire code block: ................. Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here Dim conStr As String = "Provider=Microsoft.Jet.OleDb.4.0;data source=C:\Documents and Settings\kwlehman\My Documents\Elena1.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
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:O$**************@TK2MSFTNGP12.phx.gbl... "Kevin" <Ke***@discussions.microsoft.com> schrieb: Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here Dim conStr As String = "Provider=Microsoft.Jet.OleDb.4.0;data source=C:\Documents and Settings\kwlehman\My Documents\Elena1.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
"Mythran" <ki********@hotmail.comREMOVETRAIL> 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/>
Here is the comlete code block:
.................................
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Dim conStr As String = "Provider=Microsoft.Jet.OleDb.4.0;data
source=C:\Documents and Settings\kwlehman\My Documents\Elena1.mdb"
Dim conn As OleDbConnection = New OleDbConnection(conStr)
...................................
"Herfried K. Wagner [MVP]" wrote: "Kevin" <Ke***@discussions.microsoft.com> 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=Microsoft.Jet.OleDb.4.0;data source=C:\Documents and Settings\kwlehman\My Documents\Elena1.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/>
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.EventArgs) 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
Cor,
"Cor Ligthert" <no************@planet.nl> schrieb: 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.
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/>
Herfried, Note that you actually /can/ qualify a module's member by the module name if you want to do so!
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
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. Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
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
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.EventArgs) 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
Cor,
"Cor Ligthert" <no************@planet.nl> schrieb: 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.
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/>
Herfried, Note that you actually /can/ qualify a module's member by the module name if you want to do so!
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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'...
|
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...
|
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...
|
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:...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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...
|
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...
|
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: 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,...
|
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,...
|
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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |