感谢网上的一位朋友
1///<summary>260///将集合类转换成DataTable361///</summary>462///<param name="list">集合</param>563///<returns></returns>664publicstaticDataTable ToDataTable(IList list)765{866DataTable result =newDataTable();967if(list.Count >0)1068{1169PRopertyInfo[] propertys = list[0].GetType().GetProperties();1270foreach(PropertyInfo piinpropertys)1371{1472result.Columns.Add(pi.Name, pi.PropertyType);1573}16741775for(inti =0; i < list.Count; i++)1876{1977ArrayList tempList =newArrayList();2078foreach(PropertyInfo piinpropertys)2179{2280objectobj = pi.GetValue(list[i],null);2381tempList.Add(obj);2482}2583object[] array =tempList.ToArray();2684result.LoadDataRow(array,true);2785}2886}2987returnresult;3088}
View Code