当您以管理员c#mysql身份登录时,会打开不同的表单

当您以管理员c#mysql身份登录时,会打开不同的表单,c#,mysql,C#,Mysql,因此,我用c#制作了一个使用MySql的登录表单,我想在管理员登录时,在用户数据库中弹出一个不同的表单,我在MySql上创建了一个名为permissions的列,因此如果用户有权限Admin,我想为他打开一个不同的表单,而不是普通用户,但我真的不知道如何打开那样做 守则: private void btn_Prijava_Click(object sender, EventArgs e) { try { string myConne

因此,我用c#制作了一个使用MySql的登录表单,我想在管理员登录时,在用户数据库中弹出一个不同的表单,我在MySql上创建了一个名为permissions的列,因此如果用户有权限Admin,我想为他打开一个不同的表单,而不是普通用户,但我真的不知道如何打开那样做

守则:

private void btn_Prijava_Click(object sender, EventArgs e)
    {
        try
        {
            string myConnection = "datasource=localhost;port=3306;username=root;password=";
            MySqlConnection myConn = new MySqlConnection(myConnection);

            MySqlCommand SelectCommand = new MySqlCommand(" select * from login.users where upIme='" + this.tB_upIme.Text + "' AND geslo='" + this.tB_geslo.Text + "' ;", myConn);

            MySqlDataReader myReader;
            myConn.Open();
            myReader = SelectCommand.ExecuteReader();
            int count = 0;
            while (myReader.Read())
            {
                count = count + 1;
            }
            if (count == 1)
            {
                MessageBox.Show("Uspešno ste se prijavili!");
                this.Hide();
                Form3 f3 = new Form3();
                f3.ShowDialog();
            }
            else if (count > 1)
            {
                MessageBox.Show("Dvojno uporabniško ime in geslo!");
                this.Hide();
            }
            else
                MessageBox.Show("Uporabniško ime ali geslo ni pravilno!");
            myConn.Close();
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }

如果您有
权限
列,并且对管理员用户具有值
Admin
,则可以尝试以下代码

       bool IsAdminUser=false; 
       while (myReader.Read())
        {
            count = count + 1;
            IsAdminUser = myReader["permissions"].ToString().Equals("Admin");
        }
        if (count == 1 && IsAdminUser==true)
        {
            MessageBox.Show("User is Admin!");
            this.Hide();
            AdminForm adminForm = new AdminForm ();
            adminForm.ShowDialog();
        }
        else if (count == 1)
        {
            MessageBox.Show("Uspešno ste se prijavili!");
            this.Hide();
            Form3 f3 = new Form3();
            f3.ShowDialog();
        }
        else if (count > 1)
        {
            MessageBox.Show("Dvojno uporabniško ime in geslo!");
            this.Hide();
        }

私有void cmdEnter\u单击(对象发送方,事件参数e) { 尝试 { string myConnection=“datasource=localhost;port=3306;username=root;password=1234”; MySqlConnection myConn=新的MySqlConnection(myConnection)


你有一个SQL注入漏洞。不要以纯文本形式存储密码!稍后我会更改它,但现在重要的是,如果管理员登录,我只需要打开一个不同的表单。@user3375194:欢迎你,很高兴得到你的帮助亲爱的:),不要忘记接受它。永远没有任何理由编写
?true:false
@SLaks:sorry亲爱的我不明白你的意思,你能解释一下是否有什么错误吗?@Sudhakartrapudi:你明白
x是什么意思吗?true:false
的意思吗?为什么你认为这是必要的?@SLaks:我意识到了,是的
?:
没有必要:)谢谢你的评论。欢迎来到堆栈溢出!一般来说,如果它们包括对代码意图的解释,以及为什么在不引入其他代码的情况下解决问题。
                MySqlCommand SelectCommand = new MySqlCommand(" select * from boardinghousedb.employee_table where username='" + this.txtUsername.Text + "' AND password='" + this.txtPassword.Text + "' ;", myConn);

                MySqlDataReader myReader;
                myConn.Open();
                myReader = SelectCommand.ExecuteReader();
                int count = 0;

                bool IsAdminUser = false;
                while (myReader.Read())
                {
                    count = count + 1;
                    IsAdminUser = myReader["username"].ToString().Equals("admin");
                }
                if (count == 1 && IsAdminUser == true)
                {
                    MessageBox.Show("User is Admin!");
                    this.Hide();
                    AdminForm adminForm = new AdminForm();
                    adminForm.ShowDialog();
                }
                else if (count == 1)
                {

                    this.Hide();
                    Menu f3 = new Menu();
                    f3.ShowDialog();
                }

                else if (count > 1)
                {
                    MessageBox.Show("Duplicate Username and Password . . . Access Denied", "Error Message!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    MessageBox.Show("Username and Password is Not Correct . . . Please try again", "Error Message!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    myConn.Close();
                }

                myConn.Close();
             }
                 catch (Exception ex)
                {
                MessageBox.Show(ex.Message);
                }     
    }