• List转DataTable


            public static DataTable ListToDT<T>(List<T> ls)
            {
                DataTable dt = new DataTable();
                Type tp = typeof(T);
                PropertyInfo[] pinfo = tp.GetProperties();

                foreach (PropertyInfo pi in pinfo)
                {
                    dt.Columns.Add(pi.Name);
                   
                }

                if (ls != null)
                {
                    for (int i = 0; i < ls.Count; i++)
                    {
                        IList TempList = new ArrayList();
                        foreach (System.Reflection.PropertyInfo pi in pinfo)
                        {
                            object oo = pi.GetValue(ls[i], null);
                            TempList.Add(oo);
                        }

                        object[] itm = new object[pinfo.Length];
                        //遍历ArrayList向object[]里放数据
                        for (int j = 0; j < TempList.Count; j++)
                        {
                            itm.SetValue(TempList[j], j);
                        }
                        //将object[]的内容放入DataTable
                        dt.LoadDataRow(itm, true);
                    }

                }

                return dt;
            }

  • 相关阅读:
    monit官方摘录
    monit配置文件
    monit检测语法
    monit介绍和配置
    ganglia-gmond.conf配置文件
    ganglia问题汇总
    ganglia使用nagios告警
    ganglia-gmetad 配置文件
    监控项目
    监控方案
  • 原文地址:https://www.cnblogs.com/xiguanjiandan/p/3158409.html
Copyright © 2020-2023  润新知