如何将linq查询的结果 转换为DataTable,最简单的实现方法
来源:互联网 发布:足浴软件排名 编辑:程序博客网 时间:2024/04/29 15:34
public static DataTable CopyToDataTable<T>(this IEnumerable<T> array)
{
var ret = new DataTable();
foreach (PropertyDescriptor dp in TypeDescriptor.GetProperties(typeof(T)))
ret.Columns.Add(dp.Name, dp.PropertyType);
foreach (T item in array)
{
var Row = ret.NewRow();
foreach (PropertyDescriptor dp in TypeDescriptor.GetProperties(typeof(T)))
Row[dp.Name] = dp.GetValue(item);
ret.Rows.Add(Row);
}
return ret;
}
记得添加引用空间
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Reflection;
using System.ComponentModel;
using System.Collections;
- 如何将linq查询的结果 转换为DataTable,最简单的实现方法
- 将DataTable转换为List的好处与实现方法
- 根据反射将数据库查询结果Datatable,转换为对应的Model类实体对象
- 使用linq机制 实现datatable连表查询 结果赋值到一个新的datatable
- 将Linq转换为SQL的便捷方法
- 通过JAVA反射实现简单的ORM,将查询结果封装为对象
- Linq查询结果转换为表
- 将DataTable转换为标准的JSON
- 将CString转换为float或int的最简单的方法
- linq 将单列结果集转换为集合并带人linqtosql查询
- linq to Entities,将查询语句转换为普通的SQL语句
- Linq To XML 查询,并转换为Datatable
- 对象数组转换为DataTable的方法
- C# IList转换为datatable的方法
- 如何将DataGridView转换为DataTable?
- 将Datatable数据转换为HTML方法
- 将Datatable数据转换为HTML方法 .
- mysql--mysql简单实现查询结果添加序列号的方法
- JAVA代码安全检测
- 第一部分:基础知识(第一章)传感器和服务
- 我的心路历程和未来5年规划
- openssl 验证证书是否是某个CA证书签发
- 重新编译了一个内核无法启动,
- 如何将linq查询的结果 转换为DataTable,最简单的实现方法
- Openssl验证PKCS7签名是否有效
- 一个优秀的研发团队应该具备什么特征
- 字符编码的知识
- Emboss bump mapping (浮雕效果)
- 微软资深软件工程师:阅读代码真的很难
- 检测证书是否有密钥用法
- WPF中图形表示语法详解 - Path之Data属性语法
- 我为何爱读代码?你为何也应当爱?(转)