Results 1 to 12 of 12

Thread: [RESOLVED] [2005] Class doesnt store values

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Posts
    175

    Resolved [RESOLVED] [2005] Class doesnt store values

    hi all!!
    wonder why my class doesn't store the values???

    the class

    Code:
    Imports Microsoft.VisualBasic
    
    Public Class Strings
    
        Private _user As String = ""
    
        Property User() As String
            Get
                Return _user
            End Get
            Set(ByVal value As String)
                _user = value
            End Set
        End Property
    
    
    End Class
    the login:

    Code:
     Sub dologin(ByVal Source As Object, ByVal E As EventArgs)
    
            Dim strConn As String = (ConfigurationManager.ConnectionStrings _
                ("GesQualConnectionString").ConnectionString)
    
            Dim MySQL As String = "Select ID, Utilizador , Pass ," & _
            "AlterarPass from Users Where Utilizador = '" & _
            TxtUser.Text & "' and Pass = '" & Uteis.GeraHash(TxtPass.Text) & "'"
    
            Dim MyConn As New SqlConnection(strConn)
            Dim Cmd As New SqlCommand(MySQL, MyConn)
    
            MyConn.Open()
            objDR = Cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
    
            If Not objDR.Read() Then
                LblResposta.Text = "<h1><b>User / Pass Inválidos !</b></h1></p>"
                While objDR.Read()
                    strNome = objDR("Utilizador")
                    intCode = objDR("ID")
                    bprimeirologin = objDR("AlterarPass")
                End While
    
                Session("ID") = intCode
                Session("Utilizador") = strNome
    
                Dim clsStrings As New Strings
                clsStrings.User = strNome
    
                objDR.Close()
                MyConn.Close()
            Else
                objDR.Close()
                MyConn.Open()
    
               
                If bprimeirologin Then
                    Response.Redirect("~\MudaPass.aspx")
                Else
                    Response.Redirect("~\Default.aspx")
                End If
    
            End If
    
        End Sub

    and the call:

    Code:
     Protected Sub Page_Load(ByVal sender As Object, _
        ByVal e As System.EventArgs) Handles Me.Load
    
            Dim ClsStrings As New Strings
            Label1.Text = ClsStrings.User
    
    
        End Sub

  2. #2
    Addicted Member senthilkumartd's Avatar
    Join Date
    Feb 2005
    Posts
    206

    Re: [2005] Class doesnt store values

    Code:
    Dim clsStrings As New Strings
    The above code in ur program automatically deletes the previous value. And also I can't understand what u trying to do. Because this is not declared public. Explain the code for exact answer.
    God has been pleased to place as a king or cobbler do the work sincerely

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Posts
    175

    Re: [2005] Class doesnt store values

    thanks senthilkumartd!!!
    i need to store some strings to use in other pages!
    provided by the login page, such as UserName and so on!
    wanted to keep them in the strings class
    and get them when i want to use them

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Posts
    175

    Re: [2005] Class doesnt store values

    ok it is public now but still doesn't work:

    Code:
    Public Class Strings
    
        Private Shared _user As String = ""
    
        Public Shared Property User() As String
            Get
                Return _user
            End Get
            Set(ByVal value As String)
                _user = value
            End Set
        End Property
    
    
    End Class

  5. #5
    Hyperactive Member
    Join Date
    Oct 2006
    Posts
    354

    Re: [2005] Class doesnt store values

    Your object for the Strings class are only stored for the life time of the dologin method. If you want to access the object with another method you will have to instantiate the object in the class level of whatever class dologin resides in. that way any method in the class that dologin reside in can access all public methods of the Strings class.

  6. #6
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2005] Class doesnt store values

    This is a surreal thread. I see a class designed to store a string. Almost redundant. And then nobody mentions session variables.

    Motorui, store the username in a session variable.

    Session("username") = strNome

    Then in another page,

    Label1.Text = Session("username").ToString()

  7. #7
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: [2005] Class doesnt store values

    Kudos mendhack... for something this simple, session variables is the wya to go. Even if the data was complex, creating the class, setting the properties, then STORE THE CLASS IN THE SESSION VARIABLE would be the way to go. Simply putting the data into a class doesn't make it appear on the other side. It needs to be stored and sent, jsut like anything else.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Posts
    175

    Re: [2005] Class doesnt store values

    thanks all!
    i will use session
    sorry about this but I'm still noob!
    hehehe

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Posts
    175

    Re: [RESOLVED] [2005] Class doesnt store values

    one more question
    how to add select statement value to session??

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Posts
    175

    Re: [RESOLVED] [2005] Class doesnt store values

    i tried this it does the login just fine but doesn't store the user name in session:

    Code:
     Dim strConn As String = (ConfigurationManager.ConnectionStrings _
                ("GesQualConnectionString").ConnectionString)
    
            Dim MySQL As String = "SELECT UH ," & _
            "Utilizador, LControl, CheckIn, Placa, LostFound, Admin " & _
            " FROM Users Where Utilizador = '" & _
            TxtUser.Text & "' and Pass = '" & Uteis.GeraHash(TxtPass.Text) & "'"
    
            Dim MyConn As New SqlConnection(strConn)
            Dim Cmd As New SqlCommand(MySQL, MyConn)
    
            MyConn.Open()
            objDR = Cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
    
            If Not objDR.Read() Then
                LblResposta.Text = "<h1><b>User / Pass Inválidos !</b></h1></p>"
                While objDR.Read()
                    strNome = objDR("Utilizador")
                    intCode = objDR("ID")
                End While
    
                objDR.Close()
                MyConn.Close()
    
            Else
                objDR.Close()
                MyConn.Open()
    
                Session("User") = strNome
    
    
                If bprimeirologin Then
                    Response.Redirect("~\MudaPass.aspx")
                Else
                    Response.Redirect("~\Default.aspx")
                End If
    
            End If
    
        End Sub

  11. #11
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [RESOLVED] [2005] Class doesnt store values

    1. Don't put SQL statements in session variables. You're better off creating a stored procedure that does this SELECT for you. You simply pass the username to it.

    2. You've assigned strNome in the 'if' portion of your 'if-then-else' block, but you attempt to access it in the 'else' portion. It's not going to work, since only the 'if' portion or the 'else' portion will be executed, but not both. From your code I see that Utilizador is the same as TxtUser.Text, so you should say:

    Session("User") = TxtUser.Text

    And do this before the if block.

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Posts
    175

    Re: [RESOLVED] [2005] Class doesnt store values

    i started with user name just to test it! i need to retrieve to session other
    items in the database!
    i will try with a stored procedure!
    and post here the result
    thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width