我有VS2015,实体框架6.我有一个带有一个表的数据库(登录)
FirstName, lastName, Birthdate, email, password
我还有一个文本框,按钮
tbEmail tbpass and btnLogin
如何检查文本框中的用户电子邮件是否与数据库中的用户匹配?
到目前为止,我有:
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;
}
}
}
然而,它不起作用并始终启用成功标签。我该如何解决这个问题?
答案 0 :(得分:1)
使用以下代码段尝试一次:
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;
}
}
或者,您还可以再次查看以下示例:
或者您使用个人用户帐户重构VS模板