© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
39 replies
Shogunex

✅ Getting a single value in sql db

I am currently making a information system for our project in school and I am stuck at the login part wherein I need to get the role value of the username and password so they'll go to their respective panel once they've clicked logged in. I've been searching online and couldn't find an answer.

Currently this is my code for my login button that i've followed in Youtube.

private void btnClick(object sender, RoutedEventArgs e)
{
    /* String UN = tbGetter(tbUsernameLogin);
     String PW = tbGetter(tbPasswordLogin);

     panelMaster(validLogin(UN, PW));*/

    var Username = tbUsernameLogin.Text;
    var Password = passwordBox_password.Password;

    using (UserDataContext context = new UserDataContext())
    {
        bool userFound = context.Users.Any(user => user.Name == Username && user.Password == Password);


        if (userFound)
        {
            
            
        }
        else
        {
            MessageBox.Show("User Not Found");
        }

    }



}
private void btnClick(object sender, RoutedEventArgs e)
{
    /* String UN = tbGetter(tbUsernameLogin);
     String PW = tbGetter(tbPasswordLogin);

     panelMaster(validLogin(UN, PW));*/

    var Username = tbUsernameLogin.Text;
    var Password = passwordBox_password.Password;

    using (UserDataContext context = new UserDataContext())
    {
        bool userFound = context.Users.Any(user => user.Name == Username && user.Password == Password);


        if (userFound)
        {
            
            
        }
        else
        {
            MessageBox.Show("User Not Found");
        }

    }



}


The database currently has ID, Name, Password, and Role. I need to get the Role of the current Name and Password that was used to login so i can put it in the panelMaster() so it'll go to their own panel.
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Getting coverage of a single test in VS
C#CC# / help
4y ago
✅ Transient DbContext vs DbContextFactory
C#CC# / help
2y ago
❔ Getting SQL data from a relationship table
C#CC# / help
3y ago