Register Blogs FAQ Members List Social Groups Calendar Search Today's Posts Mark Forums Read

Go Back   DeveloperBarn Forums > Programming & Scripting > .Net Development

Sponsored Links

Discuss "Class library" in the .Net Development forum.

.Net Development - Learn about the Microsoft.Net framework and how to create powerful web-based (ASP.net) and client-based (Windows Forms) applications utilizing various languages such as C#, VB.Net, J# and others.


Closed Thread
 
LinkBack (1) Thread Tools Display Modes
  1 links from elsewhere to this Post. Click to view. #1  
Old April 1st, 2008, 09:53 AM
Shem's Avatar
Barn Enthusiast
 
Join Date: Mar 2008
Posts: 263
Thanks: 31
Thanked 5 Times in 5 Posts
Rep Power: 1
Shem is on a distinguished road
Default Class library

Hi guys ( my virgin post here )

ok so after alot of research, the best way for me to re-use code is to compile a separate class assembly and include it in my solution. Then, add references to this accembly from my web project.

HOW THE HECK DO I DO THIS
what is a separate class assembly?
how do i include in my solution and reference it from my web project.



Thanks

Last edited by richyrich; May 6th, 2008 at 11:21 AM.
Sponsored Links
  #2  
Old April 1st, 2008, 09:56 AM
jmurrayhead's Avatar
The Barnfather
 
Join Date: Mar 2008
Location: Reston, VA, USA
Posts: 951
Thanks: 22
Thanked 93 Times in 90 Posts
Blog Entries: 6
Rep Power: 4
jmurrayhead is a jewel in the roughjmurrayhead is a jewel in the roughjmurrayhead is a jewel in the roughjmurrayhead is a jewel in the rough

Awards Showcase
Microsoft Windows Microsoft SQL Server Microsoft .Net Classic ASP 
Total Awards: 4

Default

You don't have to do it exactly that way. Take a look at the following: Building Layered Web Applications with Microsoft ASP.NET 2.0 - Part 1 - Imar.Spaanjaars.Com

Sure, you build separate classes and all, but it can be apart of the same solution. UNLESS, you want to reuse this code in other projects...then just compile it using the vb compiler and then in VS, go to Website on the menu and select Add Reference. Then you can reuse the code in other apps

Comments on this post
Shem agrees: tks
__________________
jmurrayhead
If you agree with me... click the icon!
If my post solved your problem, click the button in the lower right-hand corner of the post.

If you like it here...throw us a few bones to help
support us.

Join our Folding team: DeveloperBarn Folding

  #3  
Old April 1st, 2008, 10:04 AM
Shem's Avatar
Barn Enthusiast
 
Join Date: Mar 2008
Posts: 263
Thanks: 31
Thanked 5 Times in 5 Posts
Rep Power: 1
Shem is on a distinguished road
Default

cool will check out that link.

as per my previous question:
ok so i won't reuse the code in other projects, lets say this app / website
will only use these classes.

where do i store these classes, and how do i 'include / reference' them in my diff pages?

Shem
  #4  
Old April 1st, 2008, 10:08 AM
jmurrayhead's Avatar
The Barnfather
 
Join Date: Mar 2008
Location: Reston, VA, USA
Posts: 951
Thanks: 22
Thanked 93 Times in 90 Posts
Blog Entries: 6
Rep Power: 4
jmurrayhead is a jewel in the roughjmurrayhead is a jewel in the roughjmurrayhead is a jewel in the roughjmurrayhead is a jewel in the rough

Awards Showcase
Microsoft Windows Microsoft SQL Server Microsoft .Net Classic ASP 
Total Awards: 4

Default

Quote:
Originally Posted by Shem View Post
cool will check out that link.

as per my previous question:
ok so i won't reuse the code in other projects, lets say this app / website
will only use these classes.

where do i store these classes, and how do i 'include / reference' them in my diff pages?

Shem
That link will show you how to do such within the same app. Just to break it down, the code would typically be placed in the App_Code folder. The classes and the subs/functions would be public so they could be accessed throughout the application. I would place each class (based on which layer in the app it resides into a namespace - see the example in the link). Then import the namespace into the appropriate areas that they are needed.
  #5  
Old April 1st, 2008, 10:19 AM
richyrich's Avatar
Super Moderator
 
Join Date: Mar 2008
Location: Somewhere only we know...
Posts: 460
Thanks: 31
Thanked 43 Times in 43 Posts
Blog Entries: 1
Rep Power: 2
richyrich will become famous soon enoughrichyrich will become famous soon enough

Awards Showcase
JavaScript Classic ASP 
Total Awards: 2

Default

Just a an example of what I think you're after, this is what I use at the moment (admittedly after reading J's link in the past, layered apps sound the way to go), but this is what I do.

Create a seperate .vb file for your "re-useable" code. For instance, I have one for user_details.
user_details.vb. This file goes in your App_Code folder.
Code:
Imports Microsoft.VisualBasic
Imports MySql.Data.MySqlClient 'only needed because I use MySQL
 
Public Class user_details
 
  Private Shared _userref as Integer
 
  Public Shared Property userref as integer
    get
         return _userref
    end get
 
    set(ByVal value as Integer)
         _userref = value
    end set
  End Property
 
  Public shared function forename() as string
    Dim conn as new mysqlconnection("your_connection_string")
    Dim mycommand as new mysqlcommand
    mycommand.connection = conn
    Dim rs as new mysqldatareader
         Try
               mycommand.commandtext = "SELECT forename FROM users WHERE userref=?userref"
               mycommand.parameters.addwithvalue("userref",userref)
               conn.open()
               rs = mycommand.executereader()
               if rs.hasrows then
                    rs.read()
                    return rs("forename")
               else
                    return ""
               end if
               rs.close
          catch ex as exception
               return ex.message.tostring
          finally
               mycommand.dispose()
               conn.close
               conn.dispose
           end try
  End Function
 
End Class
Then in your code behind:-
Code:
Sub Page_Load
      if not ispostback then
                user_details.userref = 1 'or whatever value you want
 
                lbl_userforename.text = user_details.forename
      end if
end sub
Hope that helps Shem

Comments on this post
Shem agrees: thanks, thats what i was after
  #6  
Old April 1st, 2008, 10:27 AM
Shem's Avatar
Barn Enthusiast
 
Join Date: Mar 2008
Posts: 263
Thanks: 31
Thanked 5 Times in 5 Posts
Rep Power: 1
Shem is on a distinguished road
Default

cool thanks alot guys.
both your explanations will help me achieve my goals

@RR: thats exactly what i was after, that is what or how i want to code in .net
but will still have to go JMH's way in the end

Shem
  #7  
Old April 1st, 2008, 10:29 AM
Shem's Avatar
Barn Enthusiast
 
Join Date: Mar 2008
Posts: 263
Thanks: 31
Thanked 5 Times in 5 Posts
Rep Power: 1
Shem is on a distinguished road
Default

@ RR:
is this how you are coding in .net at the moment?
  #8  
Old April 1st, 2008, 10:29 AM
jmurrayhead's Avatar
The Barnfather
 
Join Date: Mar 2008
Location: Reston, VA, USA
Posts: 951
Thanks: 22
Thanked 93 Times in 90 Posts
Blog Entries: 6
Rep Power: 4
jmurrayhead is a jewel in the roughjmurrayhead is a jewel in the roughjmurrayhead is a jewel in the roughjmurrayhead is a jewel in the rough

Awards Showcase
Microsoft Windows Microsoft SQL Server Microsoft .Net Classic ASP 
Total Awards: 4

Default

Quote:
Originally Posted by Shem View Post
cool thanks alot guys.
both your explanations will help me achieve my goals

@RR: thats exactly what i was after, that is what or how i want to code in .net
but will still have to go JMH's way in the end

Shem
Indeed...JMH's way is much cleaner Separating all your business objects, business logic and data access layers is a great way to organize and reuse code. Keep in mind, that example I provided is very basic and once you get used to it you will be able to expand on it. Don't limit yourself to stick strictly to that example
  #9  
Old April 1st, 2008, 10:31 AM
Shem's Avatar
Barn Enthusiast
 
Join Date: Mar 2008
Posts: 263
Thanks: 31
Thanked 5 Times in 5 Posts
Rep Power: 1
Shem is on a distinguished road
Default

Quote:
Originally Posted by jmurrayhead View Post
Indeed...JMH's way is much cleaner Separating all your business objects, business logic and data access layers is a great way to organize and reuse code. Keep in mind, that example I provided is very basic and once you get used to it you will be able to expand on it. Don't limit yourself to stick strictly to that example
I'll keep that in mind, thanks
  #10  
Old April 1st, 2008, 10:37 AM
richyrich's Avatar
Super Moderator
 
Join Date: Mar 2008
Location: Somewhere only we know...
Posts: 460
Thanks: 31
Thanked 43 Times in 43 Posts
Blog Entries: 1
Rep Power: 2
richyrich will become famous soon enoughrichyrich will become famous soon enough

Awards Showcase
JavaScript Classic ASP 
Total Awards: 2

Default

Quote:
Originally Posted by Shem View Post
@ RR:
is this how you are coding in .net at the moment?
Yep...I'm still a noob and need to push this project on, so figure I'll get things working pretty well then look at making improvements at a later date...

I believe using layers you basically call the business logic layer in your top level code and this in turn makes a call to the data access layer to gather the data.

Correct me if I'm wrong J!!
Closed Thread

  DeveloperBarn Forums > Programming & Scripting > .Net Development

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

LinkBacks (?)
LinkBack to this Thread: http://www.developerbarn.com/net-development/93-class-library.html
Posted By For Type Date
DeveloperBarn Forums - ASP Help, ASP.Net Help, PHP Help, SQL Help, Tutorials, Windows Help This thread Refback April 1st, 2008 10:49 AM


All times are GMT -4. The time now is 09:29 AM.



Content Relevant URLs by vBSEO 3.2.0