首页 > 解决方案 > 用户通过 SQL 以多个权限级别登录

问题描述

我想要具有多个权限级别的用户登录,当 Perm_type 为 1 显示管理员时,我的 SQL 有 Perm_type 列,Perm_type 为 2 显示员工

我不知道如何添加代码来检查 Perm_type

SQL

我的代码是

  public Login_form()
    {
        InitializeComponent();

        /*initialize connection*/
        con = new MySqlConnection("Server=localhost;Database=demo;user=demouser;Pwd=demopassword;SslMode=none");

    }
    private void Login_btn_Click(object sender, EventArgs e) //Log In Button
    {
        string user = id_txt.Text;
        string pass = Pwd_txt.Text;
        cmd = new MySqlCommand();
        con.Open();
        cmd.Connection = con;
        cmd.CommandText = "SELECT * FROM demo_login where id='" + id_txt.Text + "' AND password='" + Pwd_txt.Text + "'";
        dr = cmd.ExecuteReader();

        if (dr.Read())
        {

                Administrator new_Form = new Administrator();
            new_Form.Show();

        }
        else
        {
            MessageBox.Show("Invalid Login please check username and password");
        }
        con.Close();
    }

标签: c#mysqllogin

解决方案


推荐阅读