Click here to Skip to main content
15,897,032 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
please ,
i want right code to make a login form system that open another form in c#2010
(for examble if i have table USERS this table include column( ID,username ,Password ,Active)in db and form login contain 2 textbox for user & pass , combobox1 for type of User and Button1 for login
[ i want connect database and on form when i type the user and type user & password if this correct system go to open another form >
{all of this through check in database}



i need help
Posted
Comments
Prerak Patel 28-Sep-11 0:03am    
No efforts! Did you even google?
Haanaza 28-Sep-11 0:14am    
thanks , but i don't under stand this["UserName='" + txtUserName.Text + "' and Password='" + txtPassword.Text + "'";] & what you mean "yourredirectedpage.aspx"
Haanaza 28-Sep-11 0:18am    
i have for examble Users (admin ,student ,teacher) i want log in form and direct jump to another form , u understand me ,
please help
Haanaza 28-Sep-11 0:23am    
i want to say too ,another form Specific to each type of user

1 solution

SqlConnection sqlcon = new SqlConnection("your connection string");
string wherstring = "UserName='" + usernametexbox.Text + "' and Password='" + passwordtextbox.Text + "'";
string strQuery="SELECT type FROM USERS "+wherstring ;
SqlCommand sqlcmd = new SqlCommand(strQuery, sqlcon);
if (sqlcon.State == ConnectionState.Open)
sqlcon.Close();
sqlcon.Open();
object obj = sqlcmd.ExecuteScalar();
sqlcon.Close();
if(obj!=null)
{
string type=convert.toint32(obj);
if(type=="admin")
{
Response.Redirect("adminpage.aspx", false);
}
else if(type=="student")
{
Response.Redirect("studentpage.aspx", false);
}
else if(type=="teacher")
{
Response.Redirect("teacherpage.aspx", false);
} 


}
else
{
//user doesnot exist
}
 
Share this answer
 
v3

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