![]() |
| |||||||
| Sponsored Links |
![]() | « Previous Thread | Next Thread » |
| | LinkBack (1) | Thread Tools | Display Modes |
#1
| ||||
| ||||
| 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
| ||||
| ||||
| 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
__________________ 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.Join our Folding team: DeveloperBarn Folding |
|
#3
| ||||
| ||||
| 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
| ||||
| ||||
| 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
| ||||
| ||||
| 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
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
|
|
#6
| ||||
| ||||
| 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
| ||||
| ||||
| @ RR: is this how you are coding in .net at the moment? |
|
#8
| ||||
| ||||
| Quote:
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
| ||||
| ||||
| Quote:
|
|
#10
| ||||
| ||||
| 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!! |
![]() |
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
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 | |