DateTable转化为泛型集合
public class ListUtil { public static List<T> ToList<T>(DataTable dt) { List<T> list = new List<T>(); T t = default(T); PropertyInfo[] propertyinfos = null; foreach (DataRow dr in dt.Rows) { t = Activator.CreateInstance<T>(); propertyinfos = t.GetType().GetProperties(); foreach (PropertyInfo pro in propertyinfos) { if (dt.Columns.Contains(pro.Name)) { object value = dr[pro.Name]; if (!value.ToString().Equals("")) { pro.SetValue(t, value.ToString(), null); } } } list.Add(t); } return list; } }