zoukankan      html  css  js  c++  java
  • List转换为DataTable

    public static DataTable ListToDataTable(IList list)
    {
    DataTable result = new DataTable();
    if (list.Count > 0)
    {
    PropertyInfo[] propertys = list[0].GetType().GetProperties();
    foreach (PropertyInfo pi in propertys)
    {
    //获取类型
    Type colType = pi.PropertyType;
    //当类型为Nullable<>时
    if ((colType.IsGenericType) && (colType.GetGenericTypeDefinition() == typeof(Nullable<>)))
    {
    colType = colType.GetGenericArguments()[0];
    }
    result.Columns.Add(pi.Name, colType);
    }
    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;
    }

  • 相关阅读:
    装配Bean
    百练
    东软小选拔
    俄罗斯乘法
    POJ
    ACdream
    javascript 链式作用域
    ie6/7 bug
    onreadystatechange 和 status
    瀑布流 <<转>>
  • 原文地址:https://www.cnblogs.com/2260827114com/p/5073076.html
Copyright © 2011-2022 走看看