Click here to Skip to main content
15,903,770 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
C#
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
        {

            LinqChatDataContext db = new LinqChatDataContext();

            var user = (from u in db.Users
                        where u.Username == Login1.UserName
                        && u.Password == Login1.Password
                        select u).SingleOrDefault();


            if (user != null)
            {
                e.Authenticated = true;
                Session["ChatUserID"] = user.UserID;
                Session["ChatUsername"] = user.Username;
            }
            else
            {
                e.Authenticated = false;
            }
        }
Posted

You have to create query like this, and read the values and convert it to object if required.
SQL
"select * from Users where Username = '" + Login1.UserName + "' and Password = '" + Password + "'"

Good practice is to use parameterized query or stored procedure instead.
 
Share this answer
 
Try as below code to get SQL Query from your LINQ Query.

C#
LinqChatDataContext db = new LinqChatDataContext();

IQueryable<User> myQuery = (from u in db.Users
                        where u.Username == Login1.UserName
                        && u.Password == Login1.Password
                        select u).SingleOrDefault();

string sqlCommand = LinqChatDataContext.GetCommand(myQuery).CommandText;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900