zoukankan      html  css  js  c++  java
  • ArrayList转换类型为DataTable类型

            /// <summary>
            /// ArrayList转换类型为DataTable
            /// </summary>
            /// <param name="list"></param>
            /// <returns></returns>
            public static DataTable ToDataTableTow(IList 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;
            }

  • 相关阅读:
    shell test -n -z
    java -d64
    shell export
    topngroupcollector
    stat 查看文件修改时间
    随机30道小学计算题02(修改)
    设计四则运算2程序单元测试用例
    学习进度02
    随机30道小学计算题02
    随机30道小学计算题01
  • 原文地址:https://www.cnblogs.com/wuhuisheng/p/2086110.html
Copyright © 2011-2022 走看看