zoukankan      html  css  js  c++  java
  • C# List集合转换成DataTable

         /// <summary>
            /// 将List集合 转换成 DataTable
            /// </summary>
            /// <param name="entitys">sellerSearchDealList是我自己定义的一个类</param>
            public static DataTable ListToTable(List<sellerSearchDealList> entitys)
            {
                DataTable dtresult = new DataTable();
                if (entitys == null || entitys.Count < 1)
                {
                    throw new Exception("");
                }
                else
                {
                    PropertyInfo[] propertys = entitys[0].GetType().GetProperties();
                    foreach (PropertyInfo pi in propertys)
                    {
                        dtresult.Columns.Add(pi.Name, pi.PropertyType);
                    }
    
                    for (int i = 0; i < entitys.Count; i++)
                    {
                        ArrayList tenpList = new ArrayList();
                        foreach (PropertyInfo pi in propertys)
                        {
                            object obj = pi.GetValue(entitys[i], null);
                            tenpList.Add(obj);
                        }
                        object[] array = tenpList.ToArray();
                        dtresult.LoadDataRow(array, true);
                    }
                }
                return dtresult;
            }
  • 相关阅读:
    SIP协议
    Jenkins 使用
    JMeter测试报告
    JMeter接口测试
    JMeter学习2
    JMeter学习1
    Docker
    WebLog Expert
    sqlmap11种常见方法
    网络
  • 原文地址:https://www.cnblogs.com/jcdd-4041/p/3538310.html
Copyright © 2011-2022 走看看