开发者

'And' operator in Linq

开发者 https://www.devze.com 2022-12-28 07:43 出处:网络
I have a query that prints userid in label1 when username is entered.Works fine; but i want to write query for username and password that prints userid. so how can i write it? i tried writing using \'

I have a query that prints userid in label1 when username is entered.Works fine; but i want to write query for username and password that prints userid. so how can i write it? i tried writing using 'and' operator but dont seems to work.

int id = (from auser in lq.logins
          where auser.username == user开发者_运维知识库NameString //&& auser.Password =pwdString
          select auser.userid).SingleOrDefault();

label1.Text = id.ToString();

Thanks Ani


It looks like you used the assignment operator = instead of the comparison operator ==. The query should be:

int id = (from auser in lq.logins
          where auser.username == userNameString && auser.Password == pwdString
          select auser.userid).SingleOrDefault();

label1.Text = id.ToString();


It probably doesn't work becase you used = instead of ==.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号