If I were you, I'd close my Connection before I'd look at anything else.
Next, I'd turn Option Strict ON. Then I'd fix all of the exceptions that
turning Option Strict ON will raise.
And remember that classes are not magic, or anything strange to you. They
are simply containers for process and data. So, for example, when you ask -
[color=blue]
> Can a class pull data from a session automatically, so all i would have to
> do is Imports app.User and then in my script just call the FullName
> property? Know what I mean?[/color]
Keep in mind that a class is just code, encapsulated in a class definition.
It can do anything that any other code can do.
Keep studying. "Imports" is a pre-processor declaration that is useful for
the developer, to prevent the developer from having to type the full
namespace every time something in that namespace is used. At run-time, it
does nothing.
One last piece of advice: When somebody gives you code, do yourself a favor
and don't use it until you understand it fully. Why? Well, for one thing,
the next time you need similar code you can write it yourself. It enhances
your skillset. And you wouldn't eat something that some stranger on the
street gave you, would you? It might be bad. So, it's not a good idea for
your program to eat code that somebody gave you off the street without your
understanding what it does, and what it might do that it should not. There's
a lot of bad code floating around out there.
--
HTH,
Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.
"David Lozzi" <dlozzi@(remove)delphi-ts.com> wrote in message
news:eI0qmHaNFHA.1884@TK2MSFTNGP15.phx.gbl...[color=blue]
> OK, so i think i got it. My code is below. It appears to work great, the
> user object is saved in the user's session state. Check out the code for
> home.aspx. Will I have to thos first 2 lines every time? Can a class pull
> data from a session automatically, so all i would have to do is Imports
> app.User and then in my script just call the FullName property? Know what
> I mean?
>
>
> *****
> in User.vb
> Imports System.Configuration
> Imports System.Data.SqlClient
>
>
> Public Class User
> Private sqlConn As String =
> ConfigurationSettings.AppSettings("ConnectionStrin g")
> Private _firstname As String
> Private _lastname As String
> Private _username As String
> Private _password As String
>
>
> Public Function Login() As Boolean
>
> _username = Replace(_username, "'", "''")
> _password = Replace(_password, "'", "''")
>
> Dim sqlQry As String = "cp_GetUser '" & _username & "'"
>
> Dim myConnection As New SqlConnection(sqlConn)
> myConnection.Open()
> Dim myCommand As New SqlCommand(sqlQry, myConnection)
>
> Dim rec As SqlDataReader
> rec = myCommand.ExecuteReader()
>
> If Not rec.Read Then
> Login = False
> Else
> If _password = rec("strPassword") Then
> _firstname = rec("strFirstName")
> _lastname = rec("strLastName")
> _password = "none"
> Login = True
> End If
> End If
> End Function
>
> Public Property FirstName() As String
> Get
> Return _firstname
> End Get
> Set(ByVal Value As String)
> _firstname = Value
> End Set
> End Property
>
> Public Sub New()
>
> End Sub
>
> Public Property LastName() As String
> Get
> Return _lastname
> End Get
> Set(ByVal Value As String)
> _lastname = Value
> End Set
> End Property
>
> Public ReadOnly Property FullName() As String
> Get
> Return _firstname & " " & _lastname
> End Get
> End Property
>
> Public ReadOnly Property FullNameRev() As String
> Get
> Return _lastname & ", " & _firstname
> End Get
> End Property
>
>
> Public Property UserName() As String
> Get
> Return _username
> End Get
> Set(ByVal Value As String)
> _username = Value
> End Set
> End Property
>
> Public Property Password() As String
> Get
> Return _password
> End Get
> Set(ByVal Value As String)
> _password = Value
> End Set
> End Property
> End Class
>
> *****
> in default.aspx
> Dim usr As New User
> usr.UserName = txtusername.Text
> usr.Password = txtpassword.Text
>
> If Not usr.Login() Then
> lblStatus.Text = "Unsuccessful. Please try again.<br>" &
> usr.UserName
> Else
> Session("UserObj") = usr
> Response.Redirect("home.aspx")
> End If
>
> *****
> in home.aspx
> 1 Dim usr As User
> 2 usr = Session("UserObj")
> 3 lblStatus.Text = "Welcome " & usr.FullName & "<br>Fullnamerev " &
> usr.FullNameRev
>
>
>
> Thanks!!
>
>
>
>
> "David Lozzi" <dlozzi@(remove)delphi-ts.com> wrote in message
> news:OWp7wiVNFHA.2580@TK2MSFTNGP09.phx.gbl...[color=green]
>> Hmm.. OK.
>>
>> I'm following you for the most part in your sample, but once it is in the
>> Session var, how do I reference it again somewhere else?
>>
>> Thanks,
>>
>> David Lozzi
>>
>>
>> "Peter MacMillan" <peter@writeopen.com> wrote in message
>> news:A5WdnXGT8L2k3dffRVn-sA@rogers.com...[color=darkred]
>>> David Lozzi wrote:
>>>> Howdy,
>>>>
>>>> I'm new to classes. Below is my class User. (is this a reserved
>>>> namespace or class?) It works great, kind of. If I specify the username
>>>> and password, the correct firstname and lastname are returned. For
>>>> example, username dlozzi, password fun. It returns David Lozzi as full
>>>> name. If I login as someone else on another computer, say username
>>>> dsmith and password fun2, the second computer displays the correct
>>>> fullname. HOWEVER if I refresh the page on the first computer where I
>>>> logged in under dlozzi, the information is now dsmith's info. I believe
>>>> I am just missing one small piece, but I just cannot find it. Should I
>>>> be using Session states along with classes?
>>>>
>>>> Thanks!
>>>>
>>>
>>>
>>> Your problem is coming from all of your methods and properties being
>>> shared. I'm not sure how to explain this without going all-out on OO
>>> methodology... "shared" means there is only one of that thing for the
>>> class.
>>>
>>> You're right to have the login method (method is an OO word for
>>> procedure/function).
>>>
>>> You want something like:
>>>
>>> Public Class User
>>> Private m_username As String
>>>
>>> Public Sub New()
>>> End Sub
>>>
>>> Public Property Username() As String
>>> Get
>>> Return m_username
>>> End Get
>>> Set(ByVal value As String)
>>> m_username = value
>>> End Set
>>> End Property
>>>
>>> Public Shared Function Login(ByVal username As String) As User
>>>
>>> Dim result As User
>>> result = new User()
>>> result.Username = username
>>> return result
>>>
>>> End Function
>>> End Class
>>>
>>>
>>> (I don't guarantee that the above will work because I just typed it out
>>> in my newsreader. It should show you what needs to be done).
>>>
>>> Now from whereever you're loging them in, you call the Login function to
>>> get a User object. You can then store that User into the Session (say,
>>> put it in Session("UserObject") or something like that.
>>>
>>> --
>>> Peter MacMillan
>>> e-mail/msn:
peter@writeopen.com icq: 1-874-927
>>>
>>> GCS/IT/L d-(-)>-pu s():(-) a- C+++(++++)>$ UL>$ P++ L+ E-(-) W++(+++)>$
>>> N o w++>$ O !M- V PS PE Y+ t++ 5 X R* tv- b++(+) DI D+(++)>$ G e++ h r--
>>> y(--)[/color]
>>
>>[/color]
>
>[/color]