尝试此代码时出现此错误:
TaxiEntities db = new TaxiEntities();
bool IsUserPassCorrected = db.tblOperators.Any(item => item.UserName.ToLower() == txtUserName.Text.ToLower() &&
item.Password == Convert.ToInt32(txtPassWord.Text));
if (!IsUserPassCorrected)
{
MessageBox.Show("Username or Password is incorrected! Please try again");
}
答案 0 :(得分:7)
由于LINQ to Entities不支持Convert.ToInt32
,因此您需要先在LINQ之外解析int
:
TaxiEntities db = new TaxiEntities();
int password = int.Parse(txtPassWord.Text);
bool IsUserPassCorrected = db.tblOperators
.Any(item => item.UserName.ToLower() == txtUserName.Text.ToLower()
&& item.Password == password);