List转换为DataTable List<Entity>
/// <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>的更多相关文章
- DataTableHelper.cs 将DataTable转换为List,将List转换为DataTable的实现类
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- 对象列表转换为DataTable或DataTable转换为对象列表.
/**********************************************************************************/ // 说明: 数据转换工具. ...
- linq之将IEnumerable<T>类型的集合转换为DataTable类型 (转载)
在考虑将表格数据导出成excel的时候,网上搜的时候找到一个特别合适的公共方法,可以将query查询出来的集合转换为datatable 需引用using System.Reflection; publ ...
- Json 字符串 转换为 DataTable数据集合
/// <summary> /// 将json转换为DataTable /// </summary> /// <param name="strJson" ...
- c#常用的Datable转换为json,以及json转换为DataTable操作方法
#region DataTable 转换为Json字符串实例方法 /// <summary> /// GetClassTypeJosn 的摘要说明 /// </summary> ...
- [工具类]泛型集合转换为DataTable
写在前面 在实际项目中,用到了将集合转换为DataTable,就试着封装了一个方法,记录一下. 代码 using System; using System.Collections.Generic; u ...
- 泛型集合转换为DataTable
在做项目中,遇到了将集合转换为DataTable的使用,在网上看了资料,在这里记录下来,分享. using System; using System.Collections.Generic; usin ...
- Expression构建DataTable to Entity 映射委托
namespace Echofool.Utility.Common { using System; using System.Collections.Generic; using System.Dat ...
- 【c#操作office】--OleDbDataAdapter 与OleDbDataReader方式读取excel,并转换为datatable
OleDbDataAdapter方式: /// <summary> /// 读取excel的表格放到DataTable中 ---OleDbDataAdapter /// </summ ...
随机推荐
- lighttpd - 配置文件
转载其他网站,收藏查看! 配置文件lighttpd.conf参数详细说明的链接和选译 发表于 2010年12月22日 http://redmine.lighttpd.net/projects/ligh ...
- redux的一些插件总结(redux-actions,reselect)
redux本身还是过于简单,实际使用的时候需要配合许多插件. 下面是一些插件与vuex的功能对比 redux-actions <=> vuex的mutation的写法 reselect & ...
- Codeforces 864E Fire(背包DP)
背包DP,决策的时候记一下 jc[i][j]=1 表示第i个物品容量为j的时候要选,输出方案的时候倒推就好了 #include<iostream> #include<cstdlib& ...
- cmder 添加到右键菜单
管理员权限打开cmde 输入: cmder /register all 回车,OK
- idea导入web项目tomcat
概述 主要分为项目配置和tomcat配置两大步骤. 一.项目配置 打开idea,选择导入项 选择将要打开的项目路径后,继续选择项目的原本类型(后续引导设置会根据原本的项目类型更新成idea的项目),此 ...
- UIViewContentMode的各种效果
UIViewContentMode的各种效果: 首先它是枚举类型的数据,表示为下所示: typedef enum { UIViewContentModeScaleToFill, ...
- hdu 5616
Jam's balance Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tot ...
- 题解【luoguP4053 bzojP1029 [JSOI2007]建筑抢修】
洛谷题链 bzoj题链 PS: \(t_i\) : 在什么时候建筑 \(i\) 自爆 \(a_i\) : 修复 \(i\) 所花时间 题解 算法:贪心+堆维护 贪心策略: 直接按 \(t\) 贪心?显 ...
- TCP ------ TCP三次握手(建立连接)及其相关内容
1.TCP客户端要连接到TCP服务器,需要经过三个过程: 以下是通过 Wireshark 抓取的三次握手数据包 → [SYN] Seq= Win= Len= MSS= → [SYN, ACK] Seq ...
- RabbitMQ基础概念(消息、队列、交换机)
1.消息的确认 RabbitMQ需要对每一条发送的消息进行确认.消费者必须通过AMQP的basic.ack命令显式地向RabbitMQ发送一个确认,或者在订阅到队列的时候就将auto_ack参数设置为 ...