Click here to Skip to main content
15,899,754 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
C#
string constr = ConfigurationManager.ConnectionStrings["MyConnection"].ToString();
 
        SqlConnection conn = new SqlConnection(constr);
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = conn;
 
SqlDataSource ads = new SqlDataSource();
 

  ads.SelectParameters.Add("UserName", this.TextBox1.Text);
  ads.SelectParameters.Add("Password", this.TextBox2.Text);
 
 ads.SelectCommand = "SELECT * FROM [Users] WHERE [UserName]= @UserName AND[Password] = @Password";
 
  //retrieve required data
   
 DataView dv = (DataView)ads.Select(DataSourceSelectArguments.Empty);
 
    //diplay error message if record is not found
     if (dv.Count == 0)
        {
 
   this.Label1.ForeColor = System.Drawing.Color.Red;
   this.Label1.Text = "Login failed. The username or password you have entered isn't valid";
            return;
        }
 
        //create Session variables
        this.Session["Username"] = dv[0].Row["Username"].ToString();
        this.Session["UserType"] = dv[0].Row["UserType"].ToString();
 
        //Redirect to respective page based on user 

             if (this.Session["UserType"].ToString().Equals("patient"))
                Response.Redirect("Patient.aspx");
 

            else if (this.Session["UserType"].ToString().Equals("doctors"))
            Response.Redirect("Doctor.aspx");
 

            else if (this.Session["UserType"].ToString().Equals("nurse"))
            Response.Redirect("Nurse.aspx");
Posted
Updated 27-Sep-11 22:35pm
v2
Comments
Prerak Patel 28-Sep-11 4:36am    
Don't repost.

1 solution

You posted the same question at Having a problem to connect different users when user logs in my Login page. I am using sqlconnection...toto my website,
There as well you did not clarify your problem, here as well your problem statement is not clear. Be assured you will not get the response until and unless you present the question in a clear and complete manner. Just putting the question number of times will not get you any answer.

If want to re-frame the question then just update it, do not repost it.
Now tell CodeProject, what error you are facing....?
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900