Question

I'm developping an application with C# and ADO.Net entity data model.

I have a table Users in my SQL Server database with 3 columns (idUser, nameUser, statusUser).

What is the code to retrieve the first user of the table that has statusUser = 0 and show her name in a label?

Was it helpful?

Solution

Since you seem to be using Entity Framework, that code would be something like this:

using (YourDatabaseContext context = new YourDatabaseContext())
{
    User firstUser = context.Users.FirstOrDefault(u => u.statusUser == 0);

    if (firstUser != null)
    {
        lblUserName.Text = firstUser.nameUser;
    } 
}

You should definitely check out some of the introductory tutorials on Entity Framework:

or just search on Google or Bing for Entity Framework introductory tutorial - there are thousands of those out there!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top