C#登录表单& ADO.net [英] C# Log in form & ADO.net

查看:108
本文介绍了C#登录表单& ADO.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请,
我想用正确的代码制作一个登录表单系统,以在c#2010中打开另一个表单
(例如,如果我有用户表,则此表在db中包含列(ID,用户名,密码,活动),并且表单登录包含2个用于用户&pass的文本框,combobox1用于User类型和Button1用于登录
[我想在输入用户名时输入数据库并在表单上输入,如果此正确的系统打开另一个表单,请输入用户名和密码>
{所有这些都通过在数据库中签入}



我需要帮助

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

推荐答案

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
}


这篇关于C#登录表单& ADO.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆