常用的DT转list<dto>方法
public static List<StudentDTO> ConvertDataTableToList<StudentDTO>(DataTable table) where StudentDTO : class, new()
{
List<StudentDTO> list = new List<StudentDTO>();
foreach (DataRow row in table.Rows)
{
StudentDTO obj = new StudentDTO();
foreach (PropertyInfo info in obj.GetType().GetProperties())
{
if (table.Columns.Contains(info.Name))
{
if (row[info.Name] != DBNull.Value)
{
info.SetValue(obj, row[info.Name], null);
}
}
}
list.Add(obj);
}
return list;
}