473,387 Members | 1,398 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Class stuff...

Ok i'm kinda new to ASP.NET. I got like 4 aspx pages right now, all with
there aspx.vb codebehind. Each of them need to connect on the same database,
so what I want to do is to create a module or a class, wich contain a
function to connect to the database.

How to I include a class or a module to my codebehind pages? May someone
give me a hint?

thx a lot guys.
Nov 17 '05 #1
7 1289
Dominic,

You need an instance of your class so that you can interact with it. For
example, if you have a class named myClass defined in myClass.vb and you
want to call a method of that class called myMethod in your ASPX page, you
would do this in your code behind:

Dim c As myClass = New myClass()
c.myMethod

(Note that this is a VERY simple example.)

One of the problems you might encounter is that once you transition to a
new page (or postback to the same page), the instance of your object will
be gone. If you need to maintain that instance, you can store it in a
Session variable.

Hope that helps.

Jim Cheshire [MSFT]
Developer Support
ASP.NET
ja******@online.microsoft.com

This post is provided as-is with no warranties and confers no rights.

--------------------
From: "+The_Taco+" <do***********@dessausoprin.com>
Subject: Class stuff...
Date: Thu, 16 Oct 2003 11:57:57 -0400
Lines: 11
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <OO**************@TK2MSFTNGP09.phx.gbl>
Newsgroups: microsoft.public.dotnet.framework.aspnet
NNTP-Posting-Host: ia-piex-gw03-fe5-1-0-1066-cpe026.vtl.net 216.113.95.26
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP09.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:184662
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet

Ok i'm kinda new to ASP.NET. I got like 4 aspx pages right now, all with
there aspx.vb codebehind. Each of them need to connect on the same database,so what I want to do is to create a module or a class, wich contain a
function to connect to the database.

How to I include a class or a module to my codebehind pages? May someone
give me a hint?

thx a lot guys.


Nov 17 '05 #2
Taco:

If I can expand some more on what Jim suggested - Microsoft Data Access
Blocks can provide you with a ready made, object oriented method of data
access.

http://msdn.microsoft.com/library/de...ml/daab-rm.asp
"+The_Taco+" <do***********@dessausoprin.com> wrote in message
news:OO**************@TK2MSFTNGP09.phx.gbl...
Ok i'm kinda new to ASP.NET. I got like 4 aspx pages right now, all with
there aspx.vb codebehind. Each of them need to connect on the same database, so what I want to do is to create a module or a class, wich contain a
function to connect to the database.

How to I include a class or a module to my codebehind pages? May someone
give me a hint?

thx a lot guys.

Nov 17 '05 #3
Elliot M. Rodriguez wrote:
Taco:

If I can expand some more on what Jim suggested - Microsoft Data Access
Blocks can provide you with a ready made, object oriented method of data
access.

http://msdn.microsoft.com/library/de...ml/daab-rm.asp
"+The_Taco+" <do***********@dessausoprin.com> wrote in message
news:OO**************@TK2MSFTNGP09.phx.gbl...
Ok i'm kinda new to ASP.NET. I got like 4 aspx pages right now, all with
there aspx.vb codebehind. Each of them need to connect on the same


database,
so what I want to do is to create a module or a class, wich contain a
function to connect to the database.

How to I include a class or a module to my codebehind pages? May someone
give me a hint?

thx a lot guys.



No you can't expand, this is a one-reply newsgroup :-) just
kidding...btw, keep in mind namespaces, something VB.NET developers may
not pay attention to or think of as much as us C# people (especially as
a beginner). If the class you create is in a different namespace, you
need to add an Imports statement at the top of your Page that is using it.

Namespaces are basically a way of grouping classes together....it's like
a label for them. It may or may not correspond to a whole project/dll,
more often not, it's more of a logical grouping.

So let's say my project is called tester. C# (and VB.NET) by default
make this the namespace of anything you create in this proj. But more
often than not, something like what you want, I would like to put that
class in a namespace called tester.dataaccess as a simple example, a
namespace I would put all data access related classes. I could declare
that namespace in my data class file (.vb or .cs), then any Page in the
tester namespace would need to add:

Imports tester.dataaccess

before using it inside, assuming they don't alter their
namespace.....now with VB.NET you somewhat rarely see namespaces; in
fact it's not really declared by VS.NET in your Page or class, e.g. In
the project properties it sets what the default namespace is and then if
your class or Page doesn't declare one, it gets that one (tester in my
example). And the IDE doesn't insert it in your code usually (whereas
VS.NET always puts it in my C# classes).....so VB.NET developers don't
'see them' as much as for simplicity, they have this default set in the
project properties....

and thank you for tuning in to my Namespace 101 lecture according to
Craig....just wanted to explain if you're really new to .NET....it's
really a simple concept that helps organize your classes....

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET

Nov 17 '05 #4
Very good recommendation! Be sure to check out ALL of the application
blocks. Very cool stuff.

Jim Cheshire [MSFT]
Developer Support
ASP.NET
ja******@online.microsoft.com

This post is provided as-is with no warranties and confers no rights.

--------------------
From: "Elliot M. Rodriguez" <elliotmrodriguezatnospamhotmail.com>
References: <OO**************@TK2MSFTNGP09.phx.gbl>
Subject: Re: Class stuff...
Date: Thu, 16 Oct 2003 13:14:23 -0400
Lines: 25
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <u#**************@TK2MSFTNGP09.phx.gbl>
Newsgroups: microsoft.public.dotnet.framework.aspnet
NNTP-Posting-Host: 208.216.254.2
Path: cpmsftngxa06.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFTN GXA05.phx.gbl!TK2MSFTNGP08
..phx.gbl!TK2MSFTNGP09.phx.gblXref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:184701
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet

Taco:

If I can expand some more on what Jim suggested - Microsoft Data Access
Blocks can provide you with a ready made, object oriented method of data
access.

http://msdn.microsoft.com/library/de...-us/dnbda/html /daab-rm.asp

"+The_Taco+" <do***********@dessausoprin.com> wrote in message
news:OO**************@TK2MSFTNGP09.phx.gbl...
Ok i'm kinda new to ASP.NET. I got like 4 aspx pages right now, all with
there aspx.vb codebehind. Each of them need to connect on the same

database,
so what I want to do is to create a module or a class, wich contain a
function to connect to the database.

How to I include a class or a module to my codebehind pages? May someone
give me a hint?

thx a lot guys.



Nov 17 '05 #5
Craig,

Thanks for that info. One clarification. Importing the namespace isn't
required. It does, however, make writing the code much easier because you
don't have to fully qualify the object when using it, and it is certainly
recommended that you do so.

Jim Cheshire [MSFT]
Developer Support
ASP.NET
ja******@online.microsoft.com

This post is provided as-is with no warranties and confers no rights.

--------------------
Date: Thu, 16 Oct 2003 12:36:08 -0500
From: Craig Deelsnyder <cd******@NOSPAMyahoo.com>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624X-Accept-Language: en-us, en
MIME-Version: 1.0
Subject: Re: Class stuff...
References: <OO**************@TK2MSFTNGP09.phx.gbl> <u#**************@TK2MSFTNGP09.phx.gbl>In-Reply-To: <u#**************@TK2MSFTNGP09.phx.gbl>
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
Message-ID: <Ow**************@tk2msftngp13.phx.gbl>
Newsgroups: microsoft.public.dotnet.framework.aspnet
NNTP-Posting-Host: 206.9.83.4
Lines: 1
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftn gp13.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:184714
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet

Elliot M. Rodriguez wrote:
Taco:

If I can expand some more on what Jim suggested - Microsoft Data Access
Blocks can provide you with a ready made, object oriented method of data
access.

http://msdn.microsoft.com/library/de...us/dnbda/html/
daab-rm.asp

"+The_Taco+" <do***********@dessausoprin.com> wrote in message
news:OO**************@TK2MSFTNGP09.phx.gbl...
Ok i'm kinda new to ASP.NET. I got like 4 aspx pages right now, all with
there aspx.vb codebehind. Each of them need to connect on the same


database,
so what I want to do is to create a module or a class, wich contain a
function to connect to the database.

How to I include a class or a module to my codebehind pages? May someone
give me a hint?

thx a lot guys.



No you can't expand, this is a one-reply newsgroup :-) just
kidding...btw, keep in mind namespaces, something VB.NET developers may
not pay attention to or think of as much as us C# people (especially as
a beginner). If the class you create is in a different namespace, you
need to add an Imports statement at the top of your Page that is using it.

Namespaces are basically a way of grouping classes together....it's like
a label for them. It may or may not correspond to a whole project/dll,
more often not, it's more of a logical grouping.

So let's say my project is called tester. C# (and VB.NET) by default
make this the namespace of anything you create in this proj. But more
often than not, something like what you want, I would like to put that
class in a namespace called tester.dataaccess as a simple example, a
namespace I would put all data access related classes. I could declare
that namespace in my data class file (.vb or .cs), then any Page in the
tester namespace would need to add:

Imports tester.dataaccess

before using it inside, assuming they don't alter their
namespace.....now with VB.NET you somewhat rarely see namespaces; in
fact it's not really declared by VS.NET in your Page or class, e.g. In
the project properties it sets what the default namespace is and then if
your class or Page doesn't declare one, it gets that one (tester in my
example). And the IDE doesn't insert it in your code usually (whereas
VS.NET always puts it in my C# classes).....so VB.NET developers don't
'see them' as much as for simplicity, they have this default set in the
project properties....

and thank you for tuning in to my Namespace 101 lecture according to
Craig....just wanted to explain if you're really new to .NET....it's
really a simple concept that helps organize your classes....

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET


Nov 17 '05 #6
gj guys, it is working perfecly

"Jim Cheshire [MSFT]" <ja******@online.microsoft.com> a écrit dans le
message de news:sy**************@cpmsftngxa06.phx.gbl...
Very good recommendation! Be sure to check out ALL of the application
blocks. Very cool stuff.

Jim Cheshire [MSFT]
Developer Support
ASP.NET
ja******@online.microsoft.com

This post is provided as-is with no warranties and confers no rights.

--------------------
From: "Elliot M. Rodriguez" <elliotmrodriguezatnospamhotmail.com>
References: <OO**************@TK2MSFTNGP09.phx.gbl>
Subject: Re: Class stuff...
Date: Thu, 16 Oct 2003 13:14:23 -0400
Lines: 25
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <u#**************@TK2MSFTNGP09.phx.gbl>
Newsgroups: microsoft.public.dotnet.framework.aspnet
NNTP-Posting-Host: 208.216.254.2
Path:

cpmsftngxa06.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFTN GXA05.phx.gbl!TK2MSFTNGP08 phx.gbl!TK2MSFTNGP09.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:184701X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet

Taco:

If I can expand some more on what Jim suggested - Microsoft Data Access
Blocks can provide you with a ready made, object oriented method of data
access.


http://msdn.microsoft.com/library/de...-us/dnbda/html
/daab-rm.asp


"+The_Taco+" <do***********@dessausoprin.com> wrote in message
news:OO**************@TK2MSFTNGP09.phx.gbl...
Ok i'm kinda new to ASP.NET. I got like 4 aspx pages right now, all with there aspx.vb codebehind. Each of them need to connect on the same

database,
so what I want to do is to create a module or a class, wich contain a
function to connect to the database.

How to I include a class or a module to my codebehind pages? May someone give me a hint?

thx a lot guys.


Nov 17 '05 #7
Dominic,

That's great to hear. Thanks for the update.

Jim Cheshire [MSFT]
Developer Support
ASP.NET
ja******@online.microsoft.com

This post is provided as-is with no warranties and confers no rights.

--------------------
From: "+The_Taco+" <do***********@dessausoprin.com>
References: <OO**************@TK2MSFTNGP09.phx.gbl> <u#**************@TK2MSFTNGP09.phx.gbl>
<sy**************@cpmsftngxa06.phx.gbl>Subject: Re: Class stuff...
Date: Thu, 16 Oct 2003 15:25:22 -0400
Lines: 68
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <ui**************@TK2MSFTNGP12.phx.gbl>
Newsgroups: microsoft.public.dotnet.framework.aspnet
NNTP-Posting-Host: ia-piex-gw03-fe5-1-0-1066-cpe026.vtl.net 216.113.95.26
Path: cpmsftngxa06.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFTN GXA07.phx.gbl!TK2MSFTNGXA0
6.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP08.phx.g bl!TK2MSFTNGP12.phx.gblXref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:184751
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet

gj guys, it is working perfecly

"Jim Cheshire [MSFT]" <ja******@online.microsoft.com> a écrit dans le
message de news:sy**************@cpmsftngxa06.phx.gbl...
Very good recommendation! Be sure to check out ALL of the application
blocks. Very cool stuff.

Jim Cheshire [MSFT]
Developer Support
ASP.NET
ja******@online.microsoft.com

This post is provided as-is with no warranties and confers no rights.

--------------------
>From: "Elliot M. Rodriguez" <elliotmrodriguezatnospamhotmail.com>
>References: <OO**************@TK2MSFTNGP09.phx.gbl>
>Subject: Re: Class stuff...
>Date: Thu, 16 Oct 2003 13:14:23 -0400
>Lines: 25
>X-Priority: 3
>X-MSMail-Priority: Normal
>X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
>X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
>Message-ID: <u#**************@TK2MSFTNGP09.phx.gbl>
>Newsgroups: microsoft.public.dotnet.framework.aspnet
>NNTP-Posting-Host: 208.216.254.2
>Path:

cpmsftngxa06.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFT NGXA05.phx.gbl!TK2MSFTNGP0

8
phx.gbl!TK2MSFTNGP09.phx.gbl
>Xref: cpmsftngxa06.phx.gblmicrosoft.public.dotnet.framework.aspnet:184701 >X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
>
>Taco:
>
>If I can expand some more on what Jim suggested - Microsoft Data Access
>Blocks can provide you with a ready made, object oriented method of data
>access.
>


http://msdn.microsoft.com/library/de...n-us/dnbda/htm l
/daab-rm.asp
>
>
>"+The_Taco+" <do***********@dessausoprin.com> wrote in message
>news:OO**************@TK2MSFTNGP09.phx.gbl...
>> Ok i'm kinda new to ASP.NET. I got like 4 aspx pages right now, all

with >> there aspx.vb codebehind. Each of them need to connect on the same
>database,
>> so what I want to do is to create a module or a class, wich contain a
>> function to connect to the database.
>>
>> How to I include a class or a module to my codebehind pages? Maysomeone >> give me a hint?
>>
>> thx a lot guys.
>>
>>
>
>
>



Nov 17 '05 #8

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

Similar topics

8
by: | last post by:
I would like to optimize my classes at run time. The question is where to put my "if" statement. -Inside __main__? if option: class Foo: def __init__: #do stuff else: class Foo: def __init__:
3
by: Fiber Optic | last post by:
I wrote a sample app to test using a function to obtain friend-level access to a templated class. However, I am getting similar errors from two separate compilers. If anyone can recommend what...
21
by: anddos | last post by:
i am just wondering what is the friend in a class , ive got a book about c++ but it dosent explain deep enough . anyone care to make a example with a few notes on what the friend can benifit from....
10
by: PengYu.UT | last post by:
Hi, A pure function is called in the base function constructor. It generate a run time error: "pure virtual method called". My problem is that class A have some derived classes. I want A's...
3
by: TamusJRoyce | last post by:
Hello. This is my first thread here. My problem has probably been came across by a lot of people, but tutorials and things I've seen don't address it (usually too basic). My problem is that I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
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...
1
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...
0
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...
0
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,...
0
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...
0
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,...

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.