Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
I have a problem in my website and I hope you could help me solve it
I have four types of users (Student, admin, instructor and coordinator)
I have a table in the database called “USERS” in this I have a field called User_type
For example admin=1 , Student=2 , etc….
In the login, I want when the user insert the information
I go and check his type, if student then create a student session and redirect to the student pages

This was my idea
the problem is how to get the USERS_Type from the database

I have this in my Login button event:
If userCount1 > 0 And paasCount1 > 0 And UserType = 1 Then
            Session("Stu") = TBUsername.Text
        ElseIf userCount1 > 0 And paasCount1 > 0 And UserType = 2 Then
            Session("Admin") = TBUsername.Text
        ElseIf userCount1 > 0 And paasCount1 > 0 And UserType = 3 Then
            Session("Coord") = TBUsername.Text
        ElseIf userCount1 > 0 And paasCount1 > 0 And UserType = 4 Then
            Session("Inst") = TBUsername.Text
            lberrorMess.Visible = True
        End If
And this the function I’m trying to do but it’s not working:
  Public Shared Function GetUserType(ByVal USER_NAME As String) As Int32
        Using con As New SqlConnection(ConfigurationManager.ConnectionStrings("mydbConnectionString").ConnectionString)
            Using cmd = New SqlCommand(sql, con)
                cmd.Parameters.AddWithValue("@USER_NAME", USER_NAME)

                Using reader = cmd.ExecuteReader()
                    If reader.HasRows Then
                        Dim type As Int32 = reader.GetInt32(0)
                        Return type
                    End If
                End Using

            End Using
        End Using
    End Function
Posted 8-Apr-13 21:42pm
Maciej Los at 9-Apr-13 2:50am
What error? Where are you stuck.
"Not working" - it is not informative...
Ali M Alramil at 9-Apr-13 3:03am
yes and i think it's informative
I wrote : "And this the function I’m trying to do but it’s not working:"
so it's not working dude
Maciej Los at 9-Apr-13 3:06am
But what "not working" you didn't wrote...
Please, be more specific. Do you think we can read in your mind or we see your project at all?
If you want help, you need to describe what is "not working".
ThePhantomUpvoter at 9-Apr-13 7:49am
You might think that it is informative but it is not. Do you call your mechanic and tell him "car broke" and expect that he would know exactly what the problem is?
Maciej Los at 9-Apr-13 3:02am
Try to add session to store user_type ("user type") rather than "stu", "admin", "coord", "inst".
Add a session varaible: "user name" and there store user name.
Use stored procedures rather than build queries in code, to avoid sql injection.
Ali M Alramil at 9-Apr-13 3:05am
my friend :
each type of user need a diffrent session I think because each type has diffrent pages totally diffrent so what do you think
how do I creat a stored procedures?
Maciej Los at 9-Apr-13 3:11am
I know that each type of user need different session. I suggest you to change logic and redirect to different page depends on "user_type". Do you know what i mean?[^][^]
Ali M Alramil at 9-Apr-13 3:38am
oh yes I got your Idea and i will Apply it
Maciej Los at 9-Apr-13 3:50am
In case when you make changes to your project and still you got problem, call again ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 484
1 Peter Leow 443
2 Sergey Alexandrovich Kryukov 288
3 Kornfeld Eliyahu Peter 270
4 Maciej Los 230

Advertise | Privacy | Mobile
Web01 | 2.8.150301.1 | Last Updated 9 Apr 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100