木子冬
程序就是规范流程下的替代品,互联网就是对应需求下的一个产业链!

导航

 
复制代码
 1 DataTable dt = new DataTable();
 2 if (_list != null)
 3 {
 4       //通过反射获取list中的字段 
 5    System.Reflection.PropertyInfo[] p = _list[0].GetType().GetProperties();
 6    foreach (System.Reflection.PropertyInfo pi in p)
 7     {
 8       dt.Columns.Add(pi.Name, System.Type.GetType(pi.PropertyType.ToString()));
 9     }
10    for (int i = 0; i < _list.Count; i++)
11    {
12        IList TempList = new ArrayList();
13         //将IList中的一条记录写入ArrayList
14        foreach (System.Reflection.PropertyInfo pi in p)
15        {
16          object oo = pi.GetValue(_list[i], null);
17          TempList.Add(oo);
18        }
19       object[] itm = new object[p.Length];
20      for (int j = 0; j < TempList.Count; j++)
21      {
22        itm.SetValue(TempList[j], j);
23      }
24      dt.LoadDataRow(itm, true);
25        }
26 }
复制代码

 

posted on   木子_冬  阅读(468)  评论(0编辑  收藏  举报
努力加载评论中...
 
点击右上角即可分享
微信分享提示