/// <summary>
/// 将List转换成DataTable
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="data"></param>
/// <returns></returns>
public static DataTable ToDataTable<T>(thisIList<T> data)
{
PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(typeof(T));
DataTable dt = newDataTable();
for(inti = ; i < properties.Count; i++)
{
PropertyDescriptor property = properties[i];
dt.Columns.Add(property.Name, property.PropertyType);
}
object[] values = newobject[properties.Count];
foreach(T item indata)
{
for(inti = ; i < values.Length; i++)
{
values[i] = properties[i].GetValue(item);
}
dt.Rows.Add(values);
}
return dt;
}

List转换为DataTable List<Entity>的更多相关文章

  1. DataTableHelper.cs 将DataTable转换为List,将List转换为DataTable的实现类

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  2. 对象列表转换为DataTable或DataTable转换为对象列表.

    /**********************************************************************************/ // 说明: 数据转换工具. ...

  3. linq之将IEnumerable<T>类型的集合转换为DataTable类型 (转载)

    在考虑将表格数据导出成excel的时候,网上搜的时候找到一个特别合适的公共方法,可以将query查询出来的集合转换为datatable 需引用using System.Reflection; publ ...

  4. Json 字符串 转换为 DataTable数据集合

    /// <summary> /// 将json转换为DataTable /// </summary> /// <param name="strJson" ...

  5. c#常用的Datable转换为json,以及json转换为DataTable操作方法

    #region  DataTable 转换为Json字符串实例方法 /// <summary> /// GetClassTypeJosn 的摘要说明 /// </summary> ...

  6. [工具类]泛型集合转换为DataTable

    写在前面 在实际项目中,用到了将集合转换为DataTable,就试着封装了一个方法,记录一下. 代码 using System; using System.Collections.Generic; u ...

  7. 泛型集合转换为DataTable

    在做项目中,遇到了将集合转换为DataTable的使用,在网上看了资料,在这里记录下来,分享. using System; using System.Collections.Generic; usin ...

  8. Expression构建DataTable to Entity 映射委托

    namespace Echofool.Utility.Common { using System; using System.Collections.Generic; using System.Dat ...

  9. 【c#操作office】--OleDbDataAdapter 与OleDbDataReader方式读取excel,并转换为datatable

    OleDbDataAdapter方式: /// <summary> /// 读取excel的表格放到DataTable中 ---OleDbDataAdapter /// </summ ...

随机推荐

  1. 洛谷 P1640 [SCOI2010]连续攻击游戏 解题报告

    P1640 [SCOI2010]连续攻击游戏 题目描述 lxhgww最近迷上了一款游戏,在游戏里,他拥有很多的装备,每种装备都有2个属性,这些属性的值用[1,10000]之间的数表示.当他使用某种装备 ...

  2. HDOJ.1010 Tempter of the Bone (DFS)

    Tempter of the Bone [从零开始DFS(1)] 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双重DFS HDOJ.1010 Tem ...

  3. 自动清理N天前的二进制日志

    这里以自动清理5天前的二进制日志为例(做了同步或依赖于二进制日志备份的请慎用): 以root身份登录数据库,执行以下命令: ; 首次设置expire_logs_days参数后需要执行flush log ...

  4. Hadoop及Zookeeper+HBase完全分布式集群部署

    Hadoop及HBase集群部署 一. 集群环境 系统版本 虚拟机:内存 16G CPU 双核心 系统: CentOS-7 64位 系统下载地址: http://124.202.164.6/files ...

  5. 第六章 指针与const

    const一词在字面上来源于常量constant,const对象在C/C++中是有不同解析的,如第二章所述,在C中常量表达式必须是编译期,运行期的不是常量表达式,因此C中的const不是常量表达式:但 ...

  6. could not calculate build plan: Plugin org.apache.maven.plugins:maven-resources-plugin:2.5 or one of(maven报错)

    could not calculate build plan: Plugin org.apache.maven.plugins:maven-resources-plugin:2.5 or one of ...

  7. Moodle配置

    Moodle配置 1.   内部设置 在 Moodle 站点管理员界面中有一系列的配置页面(可以从'设置' 块中访问 '网站管理'区).这里有一些重要的系统设置,你需要进行检查. 根据提示信息并结合实 ...

  8. flush priviliege

    grant all on *.* to usernmae@'%' identified by '*****'; flush privileges grant all on *.* to root@'% ...

  9. maven插件理解

    maven插件的主要功能是对用到的jar包进行管理,jar包先从本地仓库中获取,如果没有找到,则从远处中央仓库下载(需要联外网).本地仓库中的jar包可供所有maven工程使用,属于公共模块. mav ...

  10. 【BZOJ】1589: [Usaco2008 Dec]Trick or Treat on the Farm 采集糖果

    [算法]基环树DP [题意]给定若干有向基环树,每个点能走的最远路径长度. [题解] 参考:[BZOJ1589]Trick or Treat on the Farm 基环树裸DP by 空灰冰魂 考虑 ...