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
richyrich, April 1st, 2008 10:19 AM
Bookmarks