i have created my database as follows :
userid, password, type
Now in my login.aspx.cs
I want to code such that if userid
and password are matching and a user belongs to the type U then it will go to userpage
and if type is A then go to admin page. The code is shown here but how to send it to the type. I am having confusion of how to retrieve and compare and then redirect it to the following page.
public partial class login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string username = TextBox1.Text;
string pass = TextBox2.Text;
string utp;
string connectionString = WebConfigurationManager.ConnectionStrings["newdb"].ConnectionString;
SqlConnection con = new SqlConnection(connectionString);
con.Open();
string qry = "select * from login where uid=@username and pass=@pass";
SqlCommand cmd = new SqlCommand(qry,con);
cmd.Parameters.AddWithValue("@username",username);
cmd.Parameters.AddWithValue("@pass",pass);
SqlDataAdapter ad = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
ad.Fill(dt);
if (dt.Rows.Count > 0)
Response.Redirect("http://localhost:55575/WebSite13/admin/Adminpage.aspx");
else
{
ClientScript.RegisterStartupScript(Page.GetType(), "validation", "<script language='javascript'>alert('Invalid Username and Password')</script>");
}
}
}