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;
        }
  • 相关阅读:
    开始用博客
    nginx 移动端和PC端相互访问
    call、apply、bind的区别
    获取两个日期之间的所有日期组合
    高频前端开发问题
    图片懒加载实现
    某某公司中级前端面试题
    flex 布局
    plupload.js+php批量上传文件到阿里云oss
    H5 iframe 高度-根据内容的高度自适应 / iframe高度适配
  • 原文地址:https://www.cnblogs.com/Fooo/p/1486878.html
Copyright © 2011-2022 走看看