0
votes

I am creating login pages using asp.net with code behind in vb.net, I am newbie:D. My problem is how to pass the login name to another page. First, whenever I login it will identify if it is an administrator shown in a msgbox. The user requirement is that the employee name is displayed as login not the username. Here is my code. Thanks in advance.

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

    Dim cmd1 As New SqlCommand
    Dim rdr As SqlDataReader

    cmd1.Connection = cn
    cmd1.Connection.Open()
    cmd1.CommandText = "SELECT * from UserTable WHERE Username ='" & txt_username.Text & "'"
    rdr = cmd1.ExecuteReader

    If rdr.HasRows = True Then
        rdr.Read()
        If txt_username.Text = rdr.Item(0) And txt_password.Text = rdr.Item(3) Then
            CurPos = rdr.Item("Type")
            CurUser = rdr.Item("Username")
            CurName = rdr.Item("EmployeeName")

            If rdr.Item(4) = "ADMINISTRATOR" Then
                MsgBox("WELCOME! " & rdr.Item(4), MsgBoxStyle.Information)
                Main.lbl_name.Text = CurName.ToUpper       'it's not working
                POS.lbl_cashier.Text = CurName.ToUpper     ' it's not working
                Response.Redirect("ACESCHOOLSUPPLIES.aspx")
                cmd1.Connection.Close()
                'Me.Dispose()
            Else
                MsgBox("WELCOME! " & rdr.Item(4), MsgBoxStyle.Information)

                cmd1.Connection.Close()
                Response.Redirect("POS.aspx")

            End If
1
What errors are you getting? (if any)scartag
Please look up sql parameters to prevent sql injection attacks.Valamas
the problem is that i want to transfer login name to the ACESCHOOLSUPPLIES.aspxCarisle
@Carisle - Welcome to Stack Overflow where you can come and get all your programming questions answered. As a rule, Stack Overflow frowns upon duplicate questions especially from the same person.Kevin LaBranche

1 Answers

2
votes

A quick and dirty way to pass a variable is to use a session variable like:

Session("CurName") = CurName

Some other way: http://www.4guysfromrolla.com/articles/020205-1.aspx