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 ...
随机推荐
- caffe中的Accuracy+softmaxWithLoss
转:http://blog.csdn.net/tina_ttl/article/details/51556984 今天才偶然发现,caffe在计算Accuravy时,利用的是最后一个全链接层的输出(不 ...
- 牛客326B 背单词
传送门:https://ac.nowcoder.com/acm/contest/326/B 题意:给你一个n,你需有找有多少个长度从1~n 的单词,满足最长连续元音少于A个并且最长连续辅音长度少于B. ...
- ioctrl 获取本机IP及MAC地址
通过使用ioctl可以获得本机的一些信息,这里记录获得interface IP及MAC的过程. 1:ioctl 函数的作用是什么 man ioctl: DESCRIPTION The ioctl() ...
- stout代码分析之九:c++11容器新特性
stout大量使用了c++11的一些新特性,使用这些特性有利于简化我们的代码,增加代码可读性.以下将对一些容器的新特性做一个总结.主要两方面: 容器的初始化,c++11中再也不用手动insert或者p ...
- JS判断内容为空方法总结
HTML代码: 用户名:<input type="text" id="username"> <p style="color:red& ...
- HDU 5961 传递 BFS
题意:中文题,就是判断一个竞赛图拆成两个图,判断是否都传递 思路:分别BFS判深度即可,用这种方法注意要进行读入优化. /** @Date : 2016-11-18-20.00 * @Author : ...
- python3 mysql 时间参数错误
一.环境 mac OS + python3.6 + pymysql 二.执行 1.语句 select count(user_id) from chezhubangapppp.yfq_user wher ...
- java 错误: 找不到或无法加载主类解决方法
1.配置好jdk与jre环境变量路径 https://www.cnblogs.com/xch-yang/p/7629351.html 2.在编译和运行的时候需要注意如下格式.
- C#编写程序监测某个文件夹内是否有文件进行了增,删,改的动作?
新建一个Console应用程序,项目名称为“FileSystemWatcher”,Copy代码进,编译后就可以用了.代码如下: using System; using System.Collectio ...
- linux进程管理-定时定期执行任务
0.计划任务的命令: at 安排作业在某一时刻执行 batch 安排作业在系统负载不重时执行 crontab 安排周期性运行的作业 1.at命令用法: 安排命令或者多个命令在指定的时间运行一次 语法 ...