大家好我有一个大学项目,我正在编写一个登录屏幕,我的教科书太模糊了,我不知道如何显示一个消息框,如果用户名不在数据库内。这里是我的代码:如果用户名不在数据库中,如何显示消息框? C#
public void login()
{
//try
//{
var tbl = from s in this.database1DataSet.employee
where s.Username == userNameBox.Text
select s;
foreach (var s in tbl)
{
if (s.Username == userNameBox.Text && s.Password == passwordBox.Text)
{
MessageBox.Show("Access granted welcome " + s.fName);
this.Close();
}
else
{
MessageBox.Show("Access denied invalid login details");
}
}
//}
/*catch (SyntaxErrorException)
{
MessageBox.Show("User Does not exist");
}*/`enter code here`
**不要明文存储密码**。 – SLaks
那么,什么是不工作? – AlexB
if(tbl.Count()== 0) – ilmatte