zoukankan
html css js c++ java
NHibernate实现IList<T> 转换成DataSet yangan
支持VS2005,具体代码如下:
Code
using
System;
using
System.Data;
public
class
NHibernateHelper
{
/**/
/**/
/**/
///
<summary>
///
Ilist
<T>
转换成 DataSet
///
</summary>
///
<param name="list"></param>
///
<returns></returns>
public
static
DataSet ConvertToDataSet
<
T
>
(IList
<
T
>
list)
{
if
(list
==
null
||
list.Count
<=
0
)
{
return
null
;
}
DataSet ds
=
new
DataSet();
DataTable dt
=
new
DataTable(
typeof
(T).Name);
DataColumn column;
DataRow row;
System.Reflection.PropertyInfo[] myPropertyInfo
=
typeof
(T).GetProperties(System.Reflection.BindingFlags.Public
|
System.Reflection.BindingFlags.Instance);
foreach
(T t
in
list)
{
if
(t
==
null
)
{
continue
;
}
row
=
dt.NewRow();
for
(
int
i
=
0
, j
=
myPropertyInfo.Length; i
<
j; i
++
)
{
System.Reflection.PropertyInfo pi
=
myPropertyInfo[i];
string
name
=
pi.Name;
if
(dt.Columns[name]
==
null
)
{
column
=
new
DataColumn(name, pi.PropertyType);
dt.Columns.Add(column);
}
row[name]
=
pi.GetValue(t,
null
);
}
dt.Rows.Add(row);
}
ds.Tables.Add(dt);
return
ds;
}
}
查看全文
相关阅读:
Spring笔记:常用xml标签和属性 山上下了雪
Spring笔记:Hello World 山上下了雪
Spring笔记:bean的自动装配 山上下了雪
IntelliJ IDEA 2020.3.3 x64破解到2099年
每日长进计划
idea测试类中的测试方法没有运行按钮
删除所有的phpfpm进程命令
高质量编程
单例模式也能玩出花
宝塔Linux面板安装命令
原文地址:https://www.cnblogs.com/xlx0210/p/1539471.html
最新文章
14. ZGC垃圾收集器
13.G1垃圾收集器
Elasticsearch自动补全
安装Elasticsearch
Centos7安装Docker
Docker的基本使用
Docker部署RabbitMQ
Elasticsearch数据同步
Elasticsearch基本操作
Elasticsearch数据聚合
热门文章
Elasticsearch常用的查询
RabbitMQ基本使用
k8s基于二进制安装方法安装kubernetes1.19版本(二)
浅谈k8s网络模型及不同node上Pod如何互访
Overlay和Underlay网络协议区别及概述讲解
2021年12月cka考题总结及考试注意事项
Spring笔记:整合MyBtis 山上下了雪
Spring笔记:依赖注入 山上下了雪
Spring笔记:AOP面向切面编程 山上下了雪
Spring笔记:事务管理 山上下了雪
Copyright © 2011-2022 走看看