usando List con valores provienen de SQL

List<Foo> bar= new List<Foo>()
  new Foo(){ name= "xxx", sname= "yyy", age= 22 },
  new Foo(){ name= "zzz", sname= "ccc", age= 18 },
  new Foo(){ name= "aaa", sname= "bbb", age= 14 },
  new Foo(){ name= "ddd", sname= "fff", age= 26 },
  new Foo(){ name= "uuu", sname= "hhh", age= 17 },

I want to get the name, surname, age from a database table. How can I match the values with this list?

I want to get the data; Select name From FooBar Where Id = 4 assume that the return value is John and then I want to assign the John to name property of

List<Foo> bar= new List<Foo> 

and the question is how can I do this with ADO.NET?

preguntado el 27 de agosto de 11 a las 14:08

You'll need to provide a lot more details. Please read -

Thanks for your suggestion Jon -

What data access method? ADO.NET? Linq to SQL? Entity Framework? nHibernate? ...? -

The data access method is which I want to use : ADO.NET -

according to comments, I edit my question, still is it complex in order to understand? -

1 Respuestas

I'm not exactly sure of what you're asking, but I'll go on the assumption that you might be looking to query a list of data that was returned from the database.

You can use this code to query the list:

List<Bar> bar = new List<Bar>() 
        new Bar() { Id = 1, Name = "John Smith" }, 
        new Bar() { Id = 2, Name = "Jane Doe" }, 
        new Bar() { Id = 3, Name = "Joe Johnson" } 

//query the bar list and select the name 
string name = bar.Where(x => x.Id == 2).Select(x => x.Name).FirstOrDefault();

Respondido 27 ago 11, 23:08

I want to assign the value which return from the query to bar.Name - Csharp Er

that is to say I want to compose bar dynamically via sql query - Csharp Er

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.