我正在使用登录页面制作程序,对它进行编码时会出现此错误:运算符==无法应用于类型byte[]string的操作数

我不确定该在哪里使用或如何使用它。这是我的错误部分:

private void button1_Click(object sender, EventArgs e)
{
    if (string.IsNullOrEmpty(textBox1.Text))
    {
        MessageBox.Show("Please Enter your username.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Warning);
        textBox1.Focus();
        return;
    }
    try
    {
        using (DataEntities test = new DataEntities())
        {
            var query = from o in test.Users
                        where o.Username == textBox1.Text && o.Password == textBox2.Text
                        select o;
            if(query.SingleOrDefault() != null)
            {
                MessageBox.Show("You have been successfully logged in.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    //Add your code process login here
            }
            else
            {
                MessageBox.Show("Your username or password is incorrect.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
}


提前致谢!

最佳答案

如果您的用户名和密码字段是字节数组,则可以在进行比较之前将它们转换为字符串:

Encoding.ASCII.GetString(o.Username)== textBox1.Text

10-08 03:26