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;
            }

  • 相关阅读:
    批处理判断操作系统32位或64位,并注册服务
    VS 2008 快捷键
    VisualSVN Server导入Repository
    C++函数CString类常用函数
    委托和事件
    弄清楚类的访问符
    47-礼物的最大价值
    46-把数字翻译成字符串
    Github使用
    Hash算法相关
  • 原文地址:https://www.cnblogs.com/wuhuisheng/p/2086110.html
Copyright © 2011-2022 走看看