5

I get this error when I try this code :

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");
}
Guru Stron
  • 102,774
  • 10
  • 95
  • 132
m0n5t3r
  • 51
  • 1
  • 1
  • 3
  • use brackets and parse/tryparse – Sayse Jul 01 '13 at 11:57
  • On a side note, if your db is not case-sensitive you could leave out the `.ToLower()` which makes it cleaner to read. Also don't forget to `Dispose` your context which is best done wrapped inside a `using` block. – Silvermind Jul 01 '13 at 12:27

1 Answers1

7

Since LINQ to Entities does not support Convert.ToInt32, you need to parse to int outside LINQ first:

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);
cuongle
  • 74,024
  • 28
  • 151
  • 206