select data from a sql server database in C#

Asked

Viewed 76 times

-1

I made a precedent that takes all the data from all the columns of my sql table of interest, in my Asp application in c# I can put all the rows in a list ,but I need to refine this search by taking only all the data from one column. I researched a little and saw that with Lambda expressions this is possible, but I did not understand how to implement. Some help?

  • Send the class structure of the list. Ex. List<Classedalist>. Need the structure of the Classedalist to mount the Line

  • And one the tabular result of your previous tbm, need not include the values, only the structure

1 answer

0


Supposing that the Lista<> be a Lista<Pessoas> ListaDePessoas(), and you have all the people according to the return of your Procedure. Following this line of reasoning your Table has the Field (ID, Name, Birth, etc), Logically, each Person object in your List has a property referring to each Column.

I’m guessing you want to gather all the records of the column that represents each person’s Name.

using System.Collections.Generic;//-> responsible for providing the type List<>

Believing that your list is filled in with all the desired Tuples: you can store the desired column in another list, an array or direct in a component.

I will last a List<> to store this desired column.

List<string> ListaNomes = new List<string>();

ListaDePessoas.ForEach(delgate (Pessoas pessoa))
   ListaNomes.add(pessoa.Nome);
);

I hope to have helped, even with little information.

Browser other questions tagged

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