Home > Enterprise >  Login form application using C# and Entity Framework
Login form application using C# and Entity Framework

Time:12-30

I wrote an application in C# using Entity Framework 5.0, now I have username and password in database, I want to login with that data to my application but I can't.

This is where I'm 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();
    }
  • Related