zoukankan      html  css  js  c++  java
  • 泛型转DataTable方法

     

    /// 将集合类转换成DataTable
        
    /// </summary>
        
    /// <param name="list">集合</param>
        
    /// <returns></returns>
        public DataTable ToDataTable(List<GongGaoInfo> list)
        {
            DataTable result 
    = new DataTable();
            
    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;
        }
  • 相关阅读:
    百度云人脸识别API人脸库管理
    百度云人脸识别API人脸对比
    Linux之find命令
    Linux之grep命令
    Linux之sed命令
    LNMP Shell脚本发布
    auto_modify_ip Shell脚本安装
    JVM虚拟机详解+Tomcat性能优化
    Tomcat连接器详解
    Tomcat配置详解
  • 原文地址:https://www.cnblogs.com/Fooo/p/1486878.html
Copyright © 2011-2022 走看看