converting resultset from OleDbDataReader into list

后端 未结 3 1412
[愿得一人]
[愿得一人] 2021-01-26 16:26

Consider a Winforms app connecting to a SQL Server 2008 database and running a SQL SELECT statement:

string myConnectionString = \"Provider=SQLOLEDB         


        
3条回答
  •  别那么骄傲
    2021-01-26 17:04

    You can try something as (adapt it for your convenience):

    public class Person
    {
        public string Name { get; set; }
        public int Age { get; set; }
    }
    
    List dbItems = new List();
    
    while(myReader.Read())
    {
       Person objPerson = new Person();
    
       objPerson.Name = Convert.ToString(myReader["Name"]);
       objPerson.Age = Convert.ToInt32(myReader["Age"]);
    
       dbItems.Add(objPerson);
    }
    

提交回复
热议问题