How can I make a C# query in a SQL Server database

Asked

Viewed 500 times

-3

I have a project in development in this internship path and therefore I am working on new things. I would like to know how to do in C# a query of data present in SQL Server tables. Sorry if you are being too vague.

  • Not a question properly classified as software project. I suggest removing this tag to facilitate locating issues.

2 answers

1

There are several ways to do this as not specified what development would be Web or Desktop, in case if it is a Web app could do so using the Entityframework in your context do so:

   public List<GetPersonResult> GetPeople()
 {
       return (from p in dbContext.People
              select new GetPersonResult
              {
                   UserName = p.Username,
                   EmailAddress = p.Email
              }).ToList();
 }

 public class GetPersonResult
 {
       public string UserName{get;set;}
       public string EmailAddress{get;set;}
 }

Specify better which Web or Desktop environment.. blz

1


Boy, many paths lead to Rome...

You can use ADO.NET, Dapper or some more complex ORM. Nhibernate and Entity framework...

It seems your knowledge is very basic... You have a long way ahead... Want a hint? I would not do by ADO.NET... I would start with Dapper and then migrate to NH or EF.

I don’t know anyone who uses ADO.NET professionally hj on time....

Well the page to start understanding Dapper.net is this. https://github.com/StackExchange/dapper-dot-net

But if you get lost, you better start from scratch.... https://msdn.microsoft.com/en-us/library/dw70f090(v=vs.110). aspx

  • Thank you. Yes my knowledge in this language is very basic.

  • The goal would be to make an application . exe

Browser other questions tagged

You are not signed in. Login or sign up in order to post.