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!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.