i made an application on c# with database entity freamwork 5.0, now i have username and password in database, i want to login with that datas to my application but i cant login
and this is where im stuck:
private void login_Click(object sender, EventArgs e)
{
Database1Entities connect = new Database1Entities();
Users users = new Users();
if (users.username == usernameTextBox.Text && users.password == passwordTextBox.Text)
{
Form3 f3 = new Form3();
f3.Show();
this.Hide();
}
}
CodePudding user response:
Try something like
using var db = new Database1Entities();
var user = db.Users.Where(u => u.UserName == usernameTextBox.Text).FirstOrDefault();
if (user != null && user.password == passwordTextBox.Text)
{
Form3 f3 = new Form3();
f3.Show();
this.Hide();
}
