I have VS2015, entity framework 6. I have a database with one table (Logins)
FirstName, lastName, Birthdate, email, password
I also have a textbox(s), button
tbEmail tbpass and btnLogin
How do I check if the users email in the textbox matches one in the database?
So far I have:
protected void btnLogin_Click(object sender, EventArgs e)
{
Logins Log = new Logins();
using (LoginDataEntities lg = new LoginDataEntities())
{
string @email = tbUsernameL.Text;
string @password = tbPassL.Text;
var logged = from L in lg.Logins
where L.Username == @email
&& L.Pass == @password
select L.Username;
if (logged != null)
{
lblSuccess.Visible = true;
}
else
{
lblFail.Visible = true;
}
}
}
However, its not working and always enables the success label. How do I fix this?
Try it once with the following snippet:
using (LoginDataEntities lg = new LoginDataEntities())
{
string @email = tbUsernameL.Text;
string @password = tbPassL.Text;
var logged = lg.Logins
.SingleOrDefault(l=> l.Username == @email && l.Pass == @password);
if (logged != null) // update
{
lblSuccess.Visible = true;
}
else
{
lblFail.Visible = true;
}
}
Alternatively, can you also look at the following example again:
Or you refactorisiers the VS template with Individual User Accounts
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.