5

尝试此代码时出现此错误:

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");
}
4

1 回答 1

7

由于 LINQ to Entities 不支持Convert.ToInt32,您需要先解析到int外部 LINQ:

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);
于 2013-07-01T12:00:48.380 回答