Home > DeveloperSection > Forums > how to find user_type in asp.net?
Chintoo Semi

Total Post:135

Points:947
Posted on    November-10-2014 11:33 PM

 ASP.Net C#  SQL Server  Session 
Ratings:


 1 Reply(s)
 652  View(s)
Rate this:
I have login page with users having 3 user typs. from login im capturig user id and password. but i want to check user_type field and depending on that redirect to diferent pages after login. please advice me


john rob

Total Post:108

Points:756
Posted on    November-11-2014 1:56 AM

You have to do something like this if you want to read from DB.

SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConString"].ConnectionString);

    con.Open();

    SqlCommand cmd = new SqlCommand("SELECT User_Type FROM [User] WHERE User_Id =@userid and User_Password=@password", con);

    cmd.Parameters.AddWithValue("@userid", Convert.ToInt32(txtUserName.Text));

    cmd.Parameters.AddWithValue("@password", txtPassword.Text);

    var reader = cmd.ExecuteReader();

    if (reader.HasRows)

    {

    reader.Read();

    string userType = reader.GetString(0);

        Session["USER_ID"] = txtUserName.Text;

        Response.Redirect("Default.aspx");

    }

    else

    {

        Response.Write("Login Failed");

    } 


Don't want to miss updates? Please click the below button!

Follow MindStick