感谢网上的一位朋友

     /// <summary>
/// 将集合类转换成DataTable
/// </summary>
/// <param name="list">集合</param>
/// <returns></returns>
public static DataTable ToDataTable(IList list)
{
DataTable result = new DataTable();
if (list.Count > )
{
PropertyInfo[] propertys = list[].GetType().GetProperties();
foreach (PropertyInfo pi in propertys)
{
result.Columns.Add(pi.Name, pi.PropertyType);
} for (int i = ; 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;
}

list 转换成datatable的更多相关文章

  1. 带复杂表头合并单元格的HtmlTable转换成DataTable并导出Excel

    步骤: 一.前台JS取HtmlTable数据,根据设定的分隔符把数据拼接起来 <!--导出Excel--> <script type="text/javascript&qu ...

  2. C#_List转换成DataTable

    /// <summary> /// 讲list集合转换成datatable /// </summary> /// <param name="list" ...

  3. 将List转换成DataTable

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.D ...

  4. list转换成DataTable

    list转换成DataTable类如下: public static DataTable ToDataTable<T>(this IList<T> datas) { DataT ...

  5. 将list<对象>转换成DataTable,把DataTable转换成参数传入存储过程实现批量插入数据

    领导让在存储过程中批量添加数据,找出效率最高的,我看到后台代码后,发现可以将list<对象>转换成DataTable,把DataTable转换成参数传入存储过程实现批量插入数据,知道还有其 ...

  6. C# DataTable转换成实体列表 与 实体列表转换成DataTable

    /// <summary> /// DataTable转换成实体列表 /// </summary> /// <typeparam name="T"&g ...

  7. 获取报告 Stream转string,利用字符串分割转换成DataTable

    protected void Button1_Click(object sender, EventArgs e) { MemoryStream stream = new MemoryStream(); ...

  8. C#:CsvReader读取.CSV文件并转换成DataTable

    原文引用:https://www.codeproject.com/Articles/9258/A-Fast-CSV-Reader using LumenWorks.Framework.IO.Csv; ...

  9. 将泛类型集合List类转换成DataTable

    /// <summary> /// 将泛类型集合List类转换成DataTable /// </summary> /// <param name="list&q ...

  10. C#:CsvReader读取.CSV文件(转换成DataTable)

    原文引用:https://www.codeproject.com/Articles/9258/A-Fast-CSV-Reader using LumenWorks.Framework.IO.Csv; ...

随机推荐

  1. 京东ie6中轮播模块小图出现在大图上

    请大家给个评论,给个支持!呵呵 本人最新一套模版小清新童装母婴日韩风全屏轮播(上线风暴),在审核时审核失败,报的是“ie6中全屏海报轮播是小图出现在大图中间的兼容性错误” 而本人本机出现的是小图基本上 ...

  2. configured to save RDB snapshots, but is currently not able to persist o...

    Redis问题 MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on d ...

  3. Block Change Tracking (块改变跟踪)

    理论背景:Block ChangeTracking 是Oracle 10g里推出的特性. Block change tracking 会记录data file里每个block的update 信息,这些 ...

  4. BZOJ3127:[USACO2013OPEN]Yin and Yang

    浅谈树分治:https://www.cnblogs.com/AKMer/p/10014803.html 题目传送门:https://www.lydsy.com/JudgeOnline/problem. ...

  5. poj2228Naptime——环形DP

    题目:http://poj.org/problem?id=2228 dp[i][j][0/1]表示前i小时中第j小时睡(1)或不睡(0)的最优值: 注意第一个小时,若睡则对最终取结果有要求,即第n个小 ...

  6. 树——平衡二叉树插入和查找的JAVA实现

    package com.tomsnail.data.tree; /** * AVL二叉平衡树 * @author tomsnail * @date 2015年3月30日 下午4:35:50 */ pu ...

  7. python快速上手教程

    python版本 python目前的版本分为2.7和3.5,两种版本的代码目前无法兼容,查看python版本号: python --version 基本数据类型 数字类型 整型和浮点型数据和其它编程语 ...

  8. 【转】unittest执行测试用例的N种姿势总结

    原文地址:https://www.cnblogs.com/fighter007/p/9514453.html 1.我们写几个方法,用来做测试用例 2.我们在另一文件中引用这个模块下面的所有类方法,先看 ...

  9. C# 把datagridview控件上的表格输出到excel文件

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

  10. 初步使用redis

    1.导入jar包 2.新建类: public class JedisAdapter { private static final Logger logger = LoggerFactory.getLo ...