Click here to Skip to main content
Rate this: bad
good
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
            Response.Redirect("StudentProfile.aspx")
        ElseIf userCount1 > 0 And paasCount1 > 0 And UserType = 2 Then
            Session("Admin") = TBUsername.Text
            Response.Redirect("AdminProfile.aspx")
        ElseIf userCount1 > 0 And paasCount1 > 0 And UserType = 3 Then
            Session("Coord") = TBUsername.Text
            Response.Redirect("CoordinatorProfile.aspx")
        ElseIf userCount1 > 0 And paasCount1 > 0 And UserType = 4 Then
            Session("Inst") = TBUsername.Text
            Response.Redirect("InstProfile.aspx")
        Else
            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
        Const sql = "SELECT USER_TYPE FROM DIP_USERS where USER_NAME = @USER_NAME"
        Using con As New SqlConnection(ConfigurationManager.ConnectionStrings("mydbConnectionString").ConnectionString)
            Using cmd = New SqlCommand(sql, con)
 
                cmd.Parameters.AddWithValue("@USER_NAME", USER_NAME)
                con.Open()
 

                Using reader = cmd.ExecuteReader()
                    If reader.HasRows Then
                        reader.Read()
 
                        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
Comments
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?
 
thanks
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?
http://msdn.microsoft.com/en-us/library/ms178581%28v=vs.100%29.aspx[^]
http://msdn.microsoft.com/en-us/library/ms187926.aspx[^]
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 520
1 Maciej Los 290
2 Richard MacCutchan 265
3 BillWoodruff 265
4 Suraj Sahoo | Coding Passion 155
0 OriginalGriff 8,764
1 Sergey Alexandrovich Kryukov 7,437
2 DamithSL 5,639
3 Maciej Los 5,279
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web02 | 2.8.1411028.1 | Last Updated 9 Apr 2013
Copyright © CodeProject, 1999-2014
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