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?

有帮助吗?

解决方案

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!

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top