开发者

using List with values come from SQL

开发者 https://www.devze.com 2023-03-31 08:49 出处:网络
List<Foo> bar= new List<Foo>() { new Foo(){ name= \"xxx\", sname= \"yyy\", age开发者_如何学C= 22 },
List<Foo> bar= new List<Foo>()
{
  new Foo(){ name= "xxx", sname= "yyy", age开发者_如何学C= 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?


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();
0

精彩评论

暂无评论...
验证码 换一张
取 消