HOW TO FIND USER_TYPE IN ASP.NET?

Chintoo Semi

Total Post:135

Points:947
Posted by  Chintoo Semi
 1073  View(s)
Ratings:
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
  1. john rob

    Post:108

    Points:756
    Re: how to find user_type in asp.net?

    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");
        } 

      Modified On Apr-06-2018 05:33:10 AM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!