zoukankan      html  css  js  c++  java
  • 将集合类转换成DataTable

     /// <summary>        

    /// 将集合类转换成DataTale        

    /// </summary>        

    /// <param name="list">集合</param>        

    /// <returns></returns>        

    public static DataTable ToDataTable(IList list)         {            

    DataTable result = new DataTable();            

    if (list == null)            

    {                

    return result;            

    }

     if (list.Count > 0)            

    {                

    PropertyInfo[] propertys = list[0].GetType().GetProperties();                

    foreach (PropertyInfo pi in propertys)                

    {                    

    result.Columns.Add(pi.Name, pi.PropertyType);                

    }

     for (int i = 0; i < list.Count; i++)                

    {                    

    ArrayList tempList = new ArrayList();                    

    foreach (PropertyInfo pi in propertys)                    

    {                        

    object obj = pi.GetValue(list[i], null);                        

    tempList.Add(obj);                    

    }                    

    object[] array = tempList.ToArray();                    

    result.LoadDataRow(array, true);                

    }            

    }            

    return result;        

    }

  • 相关阅读:
    bzoj 3308 九月的咖啡店
    8.13模拟赛
    8.10模拟赛
    8.9模拟赛
    8.8模拟赛
    Codeforces Round #406 (Div. 2) D. Legacy (线段树建图dij)
    BZOJ 2957: 楼房重建 (分块)
    SPOJ BGSHOOT
    Codeforces Round #404 (Div. 2) E. Anton and Permutation(树状数组套主席树 求出指定数的排名)
    Lightoj-1356 Prime Independence(质因子分解)(Hopcroft-Karp优化的最大匹配)
  • 原文地址:https://www.cnblogs.com/rukialu/p/4120299.html
Copyright © 2011-2022 走看看