Class stuff...

T

+The_Taco+

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.
 
J

Jim Cheshire [MSFT]

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
(e-mail address removed)

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

--------------------
 
C

Craig Deelsnyder

Elliot said:
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/default.asp?url=/library/en-us/dnbda/html/daab-rm.asp

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....
 
J

Jim Cheshire [MSFT]

Very good recommendation! Be sure to check out ALL of the application
blocks. Very cool stuff.

Jim Cheshire [MSFT]
Developer Support
ASP.NET
(e-mail address removed)

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

--------------------
 
J

Jim Cheshire [MSFT]

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
(e-mail address removed)

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

--------------------
 
T

+The_Taco+

gj guys, it is working perfecly

Jim Cheshire said:
Very good recommendation! Be sure to check out ALL of the application
blocks. Very cool stuff.

Jim Cheshire [MSFT]
Developer Support
ASP.NET
(e-mail address removed)

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

--------------------
From: "Elliot M. Rodriguez" <elliotmrodriguezatnospamhotmail.com>
References: <[email protected]>
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#[email protected]>
Newsgroups: microsoft.public.dotnet.framework.aspnet
NNTP-Posting-Host: 208.216.254.2
Path:
cpmsftngxa06.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP08
phx.gbl!TK2MSFTNGP09.phx.gbl
Xref: 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/default.asp?url=/library/en-us/dnbda/html
/daab-rm.asp
 
J

Jim Cheshire [MSFT]

Dominic,

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

Jim Cheshire [MSFT]
Developer Support
ASP.NET
(e-mail address removed)

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

--------------------
From: "+The_Taco+" <[email protected]>
References: <[email protected]>
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: <[email protected]>
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!TK2MSFTNGXA07.phx.gbl!TK2MSFTNGXA0
6.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
Xref: 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 said:
Very good recommendation! Be sure to check out ALL of the application
blocks. Very cool stuff.

Jim Cheshire [MSFT]
Developer Support
ASP.NET
(e-mail address removed)

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

--------------------
From: "Elliot M. Rodriguez" <elliotmrodriguezatnospamhotmail.com>
References: <[email protected]>
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#[email protected]>
Newsgroups: microsoft.public.dotnet.framework.aspnet
NNTP-Posting-Host: 208.216.254.2
Path:
cpmsftngxa06.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP0 8
phx.gbl!TK2MSFTNGP09.phx.gbl
Xref: 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/default.asp?url=/library/en-us/dnbda/htm l
/daab-rm.asp
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top