tags:

views:

46

answers:

2

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 == userNameString //&& auser.Password =pwdString
          select auser.userid).SingleOrDefault();

label1.Text = id.ToString();

Thanks Ani

+1  A: 

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

Marcelo Cantos
Thanks..that was my bad..
Ani
Ani, Mark this as answer.
Raj Kaimal
+1  A: 

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();
Matt Olenik
Thanks a lot...my bad...
Ani
can u also tell me how to write inset quer in Linq.
Ani
@Ani: you definitely have to read this: http://weblogs.asp.net/scottgu/archive/2007/05/19/using-linq-to-sql-part-1.aspx
zerkms
@Zerkms Thanks..
Ani