C#将list转换为datatable
DataTable dt = new DataTable();
if (_list != null)
{
//通过反射获取list中的字段
System.Reflection.PropertyInfo[] p = _list[].GetType().GetProperties();
foreach (System.Reflection.PropertyInfo pi in p)
{
dt.Columns.Add(pi.Name, System.Type.GetType(pi.PropertyType.ToString()));
}
for (int i = ; i < _list.Count; i++)
{
IList TempList = new ArrayList();
//将IList中的一条记录写入ArrayList
foreach (System.Reflection.PropertyInfo pi in p)
{
object oo = pi.GetValue(_list[i], null);
TempList.Add(oo);
}
object[] itm = new object[p.Length];
for (int j = ; j < TempList.Count; j++)
{
itm.SetValue(TempList[j], j);
}
dt.LoadDataRow(itm, true);
}
}
C#将list转换为datatable的更多相关文章
- 对象列表转换为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 ...
- 【c#操作office】--OleDbDataAdapter 与OleDbDataReader方式读取excel,并转换为datatable
OleDbDataAdapter方式: /// <summary> /// 读取excel的表格放到DataTable中 ---OleDbDataAdapter /// </summ ...
- C#基础知识之泛型集合转换为DataTable
在做项目中,遇到了将集合转换为DataTable的使用,在网上看了资料,在这里记录下来,分享. using System; using System.Collections.Generic; usin ...
- Enumerable转换为DataTable
今天在项目组公共类库中发现一个 Enumerable类型转换为DataTable,写的挺精简的,拿出来跟大家共享一下. using System; using System.Collections.G ...
- 把List<T>转换为DataTable
下面这个学习,把List<T>转换为Datatable. 下面先创建一个对象T: class Ay { private int _ID; public int ID { get { ret ...
随机推荐
- hdu 4005 The war
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4005 In the war, the intelligence about the enemy is ...
- Leetcode#71 Simplify Path
原题地址 用栈保存化简后的路径.把原始路径根据"/"切分成若干小段,然后依次遍历 若当前小段是"..",弹栈 若当前小段是".",什么也不做 ...
- Winform 打印PDF顺序混乱,获取打印队列
工作中PDF打印顺序混乱着实让我疼痛了好久,其实决绝方法非常简单,但没有想到这个点子的时候确实让我走了很多弯路 这里文章写出来并不是为了炫耀什么,只是觉得发现些好东西就分享出来而已,同时也做个记录,方 ...
- swappiness
在ubuntu 里面,swappiness的值的大小对如何使用swap分区是有着很大的联系的.swappiness=0的时候表示最大限度使用物理内存,然后才是 swap空间,swappiness=10 ...
- POJ 1279 Art Gallery(半平面交求多边形核的面积)
题目链接 题意 : 求一个多边形的核的面积. 思路 : 半平面交求多边形的核,然后在求面积即可. #include <stdio.h> #include <string.h> ...
- 自制 JS.format带分页索引
//第一参数是:Json对象,第二个是 序号 第三个 页数 第四 当前页数String.prototype.format = function (args, sid, pagesi ...
- E文阅读
Lesson 9 A cold welcome 冷遇 What does 'a cold welcome' refer to?On Wednesday evening, we went to the ...
- android模拟器(genymotion)+appium+python 框架执行基本原理(目前公司自己写的)
android模拟器(genymotion)+appium+python 框架执行的基本过程: 1.Push.initDate(openid)方法 //业务数据初始化 1.1 v5db.p ...
- 有N个大小不等的自然数(1--N),请将它们由小到大排序。要求程序算法:时间复杂度为O(n),空间复杂度为O(1)。
#include<stdio.h> int main() { ]={,,,,,,,,}; int i,tmp; ;i<;i++) { ) { tmp=a[i]; a[i]=a[a[i ...
- Fuzzy test
参考:http://baike.baidu.com/view/3679678.htm http://en.wikipedia.org/wiki/Fuzz_testing 就是模糊测试,在网上看到也叫f ...