문제

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