我有这样的数据表。
uid m_code pass roleID
1 F2 F2 2
2 S2 S2 0
我想让用户根据他们的角色登录。
我尝试使用此代码,但它根本不起作用。非常感谢任何帮助。
string user = textBox1.Text;
string pass = textBox2.Text;
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conString"].ConnectionString);
SqlCommand cmd = new SqlCommand("select * from login where m_code='" + user + "' and pass='" + pass + "'", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
if(dt.Columns[3].ToString() == "0")
{
this.Hide();
StudentUI s = new StudentUI();
s.Show();
}
if (dt.Columns[3].ToString() == "1")
{
this.Hide();
TeacherUI t = new TeacherUI();
t.Show();
}
if (dt.Columns[3].ToString() == "2")
{
FacultyUI f = new FacultyUI();
f.Show();
}
else
{
MessageBox.Show("Login Failed");
}