运算符’==’不能应用于’byte ‘和’string’类型的操作数

我正在编写一个带有登录页面的程序,编码时出现了这个错误:运算符==不能应用于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