I am looking for a way to loop a DataSet to fill a set List the data in the the DataSet could be in multiple DataTables in the DataSet. I have a object that has the list of column names that are needed. If I loop the object to the Dataset it will not work.
public List<Customer> BuildCustomerList(DataSet ds, Customer oCustomer)
{
List<Customer> lCustomers = new List<Customer>();
foreach (PropertyInfo p in typeof(Customer).GetProperties())
{
Customer oC = new Customer();
foreach(DataRow dr in ds.Tables[0].Rows)
{
foreach(DataColumn dc in ds.Tables[0].Columns)
{
if(p.Name == dc.ColumnName)
{
p.SetValue(oC, dr[dc].ToString());
}
}
}
lCustomers.Add(oC);
}
return lCustomers;
}
I did look at How to Convert DataTable to List using Reflections This will work if I am using a DataTable but I am not sure how to make it work with a DataSet which has multiple DataTables.
Aucun commentaire:
Enregistrer un commentaire