C# List集合转换成DataTable
2014-02-05 16:08
495 查看
/// <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; }
相关文章推荐
- C# 把List 集合转换成DataTable
- C#将DataTable转换成单个T实体和List<T>集合
- DataTable转换list泛型集合(反射)
- c# Json List<T> DataTable 数据相互转换
- 再谈使用Emit把Datatable转换为对象集合(List<T>)
- C# DataTable 和List之间相互转换的方法[转]
- C#中对象,字符串,dataTable、DataReader、DataSet,对象集合转换成Json字符串方法。
- 将泛类型集合List类转换成DataTable
- 将DataTable转换List 集合
- 将Datatable转换成实体List集合的方法
- DataTable类型对象转换为List集合
- C#控制台基础 List泛型集合与对应的数组相互转换实现代码
- 将泛类型集合List类转换成DataTable
- C#之DataTable与实体集合相互转换
- C# 中如何将List<string>里的集合转换成字符串并按指定的字符进行分隔?
- 将泛类型集合List类转换成DataTable
- c# Json List<T> DataTable 数据相互转换
- C#反射实现将DataTable转换为List<T>
- C# DataTable 和List之间相互转换的方法
- DataSet、DataTable转换List(泛型集合与DataSet互相转换 )