会员
众包
新闻
博问
闪存
赞助商
HarmonyOS
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
Simplefool's Blog
Simplefool技术专栏
博客园
首页
新随笔
订阅
管理
NHibernate实现IList<T> 转换成DataSet
支持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;
}
}
posted @
2009-08-05 13:09
yangan-wu2008
阅读(
511
) 评论(
0
)
收藏
举报
刷新页面
返回顶部
公告