list转换成datatable

王朝学院·作者佚名  2016-08-27
窄屏简体版  字體: |||超大  

感谢网上的一位朋友

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

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航