Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 登录后在下一个表单中显示用户信息_C#_Mysql_Forms - Fatal编程技术网

C# 登录后在下一个表单中显示用户信息

C# 登录后在下一个表单中显示用户信息,c#,mysql,forms,C#,Mysql,Forms,我需要帮助,我的问题是我想在下一个表单中显示用户信息,就像我在开始表单中登录时一样: 起始形式 这是我的登录代码: private void btnOK_Click(object sender, EventArgs e) { Boolean exist = false; MainForm mf = new MainForm(); if (txtUser.Text == "" || txtPass.Text == "")

我需要帮助,我的问题是我想在下一个表单中显示用户信息,就像我在开始表单中登录时一样:

起始形式

这是我的登录代码:

 private void btnOK_Click(object sender, EventArgs e)
    {
        Boolean exist = false;
        MainForm mf = new MainForm();
        if (txtUser.Text == "" || txtPass.Text == "")
        {
            MessageBox.Show("Please Input Logon ID and Password", "ERROR", MessageBoxButtons.RetryCancel);

        }

        else
        {
            conn = koneksyon.getConnect();
            conn.Open();
            cmd = new SqlCommand("select Username,Password from Staff where Username = '" + txtUser.Text + "' AND Password = '" + txtPass.Text + "'", conn);
            dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                exist = true;

                txtUser.Text = dr[0].ToString();
                txtPass.Text = dr[1].ToString();

            }
            if (exist == true)
            {
                mf.Show();
                this.Hide();

            }
            else
            {
                MessageBox.Show("INCORRECT Logon ID or password", "INVALID", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtUser.Clear();
                txtPass.Clear();
                txtUser.Focus();
            }
            conn.Close();
            dr.Dispose();
            cmd.Dispose();
        }
    }
现在我的问题是我想在输入时显示它

Username=admin,Password=123456它将转到下一个表单并显示此信息

[![表格2][2]][2]


这是我登录时的信息,我如何才能做到这一点?我没有任何代码,用于显示,需要帮助!谢谢在MainForm构造函数中,您必须在括号之间放置一些变量。 i、 e.在主表格中使用以下内容:

public MainForm(string _staffID, string _firstName, string _lastName)
{
     InitializeComponent();

     txtStaffID.Text = _staffID;
     txtFisrtName.Text = _firstName;
     txtLastName.Text = _lastName;
}
现在,如果要从另一个窗体显示MainForm,请使用以下代码:

string StaffID = "Fill Yourself as you want";
string FisrtName = "Fill Yourself as you want";
string LastName = "Fill Yourself as you want";
MainForm mf = new MainForm(StaffID, FisrtName, LastName);
mf.Show();

我希望这会有所帮助。

在MainForm构造函数中,必须在括号之间放置一些变量。 i、 e.在主表格中使用以下内容:

public MainForm(string _staffID, string _firstName, string _lastName)
{
     InitializeComponent();

     txtStaffID.Text = _staffID;
     txtFisrtName.Text = _firstName;
     txtLastName.Text = _lastName;
}
现在,如果要从另一个窗体显示MainForm,请使用以下代码:

string StaffID = "Fill Yourself as you want";
string FisrtName = "Fill Yourself as you want";
string LastName = "Fill Yourself as you want";
MainForm mf = new MainForm(StaffID, FisrtName, LastName);
mf.Show();

我希望这会有帮助。

@HiDeo感谢您编辑sirTry输入
admin'--作为用户名-然后您可能会意识到为什么参数化查询如此重要。谷歌“小鲍比桌子”@MattWilko-先生,你能给我看看吗,我不知道怎么做?谢谢你不知道怎么用谷歌搜索吗?@HiDeo感谢你编辑sirTry input
admin'--作为用户名-然后您可能会意识到为什么参数化查询如此重要。谷歌“小鲍比桌子”@MattWilko-先生,你能给我看看吗,我不知道怎么做?谢谢你不知道怎么用谷歌搜索?