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;
}
}
查看全文
相关阅读:
使用微软TFS代码管理工具和在金山快盘上搭建SVN的使用方法
微软的Windows8安装体验
软件注册码随笔
软件注册码(算法一DES)
PHP连接SAE平台MYSQL
一点一滴《C++处理数据》
BouncyCastle.Crypto的RSA算法调用源码
一点一滴《C++学习》
软件注册码(算法二Rijndael)
Web 应用程序的程序常见安全防范
原文地址:https://www.cnblogs.com/xlx0210/p/1539471.html
最新文章
What Every Computer Programmer Should Know About Windows API, CRT, and the Standard C++ Library
SIP指南
海明码计算及其纠错原理网络文摘总结
SDK与MFC消息相关
[Linux][Ubuntu]在Ubuntu 12.10中安装和配置vmware tools
[Linux][Ubuntu]VMware下Ubuntu 13.04共享文件夹失效的解决方案
在Windows下使用iPython
[C][C++]长度、大小等的详解:sizeof, strlen, size...
前端开发:问题汇总
C# RSA2 登录新浪微博
热门文章
世界完全对称日计算(C#)
WINFORM自定义皮肤制作(上)
vs2017相关配置
VAssistX插件
Qt5.9.9+Visoul Studio2013编译安装
vs2017+Qt5.12.12设置界面角标和exe图标
Qt界面状态栏
VS2017设置默认WindowSDK版本
大端和小端
Qt窗口置顶激活
Copyright © 2011-2022 走看看